Skip to content

Commit

Permalink
[FIX] account: fix number_next on account.journal
Browse files Browse the repository at this point in the history
During the creation of the journal, the number_next field was
editable even without sequence_id. Furthermore, if the sequence_id
had use_date_range set to True and didn't have any ir.sequence.date_range,
a new ir.sequence.date_range was created without the right number_next.
This behavior avoided the user to create a new journal starting with number 200,
for example.
  • Loading branch information
smetl committed Feb 14, 2017
1 parent 2f41aaa commit 3472e62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions addons/account/models/account.py
Expand Up @@ -258,19 +258,19 @@ def _default_outbound_payment_methods(self):
]

@api.multi
@api.depends('sequence_id.use_date_range', 'sequence_id.implementation', 'sequence_id.date_range_ids')
@api.depends('sequence_id', 'sequence_id.use_date_range', 'sequence_id.implementation', 'sequence_id.date_range_ids')
def _compute_sequence_show_number_next(self):
'''Compute 'sequence_show_number_next' if the next number can be changed by the user.'''
for journal in self:
sequence = journal.sequence_id.get_current_sequence()
# May return ir.sequence or ir.sequence.date_range
if hasattr(sequence, 'implementation') and sequence.implementation == 'no_gap':
if not sequence or hasattr(sequence, 'implementation') and sequence.implementation == 'no_gap':
journal.sequence_show_number_next = False
else:
journal.sequence_show_number_next = True

@api.multi
@api.depends('sequence_id.use_date_range', 'sequence_id.implementation', 'sequence_id.date_range_ids',
@api.depends('sequence_id', 'sequence_id.use_date_range', 'sequence_id.implementation', 'sequence_id.date_range_ids',
'sequence_id.date_range_ids.number_next_actual', 'sequence_id.number_next_actual')
def _compute_sequence_number_next(self):
'''Compute 'sequence_number_next' according to the current sequence in use,
Expand All @@ -285,8 +285,9 @@ def _inverse_sequence_number_next(self):
'''Inverse 'sequence_number_next' to edit the current sequence next number.
'''
for journal in self:
sequence = journal.sequence_id.get_current_sequence()
sequence.number_next = journal.sequence_number_next
if journal.sequence_number_next:
sequence = journal.sequence_id.get_current_sequence()
sequence.number_next = journal.sequence_number_next

@api.one
@api.constrains('currency_id', 'default_credit_account_id', 'default_debit_account_id')
Expand Down
1 change: 1 addition & 0 deletions odoo/addons/base/ir/ir_sequence.py
Expand Up @@ -222,6 +222,7 @@ def _create_date_range_seq(self, date):
'date_from': date_from,
'date_to': date_to,
'sequence_id': self.id,
'number_next_actual': self.number_next,
})
return seq_date_range

Expand Down

0 comments on commit 3472e62

Please sign in to comment.