[FIX] base, account: fix test for 2020

When `invoice_sequence_number_next` is set in [1], the move date is not
taken into account to find a corresponding `ir.sequence.date_range` in
[2]. We use the current date instead.

However, when the move is posted we use its date to find the
`ir.sequence.date_range` [3]. This leads to an inconsistency: we set
`invoice_sequence_number_next` on the `ir.sequence.date_range` of the
current date, but at posting we use the `ir.sequence.date_range` of the
move date.

The fix is to take into account the move date when we set
`invoice_sequence_number_next`.

[1] https://github.com/odoo/odoo/blob/40c8da4bd47d99a97b7231f2749c8e981f35a1a0/addons/account/tests/test_account_move_in_invoice.py#L829
[2] https://github.com/odoo/odoo/blob/40c8da4bd47d99a97b7231f2749c8e981f35a1a0/addons/account/models/account_move.py#L1153
[3] https://github.com/odoo/odoo/blob/40c8da4bd47d99a97b7231f2749c8e981f35a1a0/addons/account/models/account_move.py#L2096

closes odoo/odoo#42580

X-original-commit: 45d126405b030610fc66b8557a668f0d61e129dc
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-01-02 12:49:13 +00:00
parent 3a541a8ae1
commit dc55cc6468
2 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -1127,7 +1127,7 @@ class AccountMove(models.Model):
for move in group:
prefix, dummy = sequence._get_prefix_suffix(date=move.invoice_date or fields.Date.today(), date_range=move.invoice_date)
number_next = sequence._get_current_sequence().number_next_actual
number_next = sequence._get_current_sequence(sequence_date=move.date).number_next_actual
move.invoice_sequence_number_next_prefix = prefix
move.invoice_sequence_number_next = '%%0%sd' % sequence.padding % number_next
treated |= move
@@ -1149,7 +1149,7 @@ class AccountMove(models.Model):
nxt = re.sub("[^0-9]", '', move.invoice_sequence_number_next)
result = re.match("(0*)([0-9]+)", nxt)
if result and sequence:
date_sequence = sequence._get_current_sequence()
date_sequence = sequence._get_current_sequence(sequence_date=move.date)
date_sequence.number_next_actual = int(result.group(2))
def _compute_payments_widget_to_reconcile_info(self):
+4 -4
View File
@@ -100,20 +100,20 @@ class IrSequence(models.Model):
seq.write({'number_next': seq.number_next_actual or 1})
@api.model
def _get_current_sequence(self):
def _get_current_sequence(self, sequence_date=None):
'''Returns the object on which we can find the number_next to consider for the sequence.
It could be an ir.sequence or an ir.sequence.date_range depending if use_date_range is checked
or not. This function will also create the ir.sequence.date_range if none exists yet for today
'''
if not self.use_date_range:
return self
now = fields.Date.today()
sequence_date = sequence_date or fields.Date.today()
seq_date = self.env['ir.sequence.date_range'].search(
[('sequence_id', '=', self.id), ('date_from', '<=', now), ('date_to', '>=', now)], limit=1)
[('sequence_id', '=', self.id), ('date_from', '<=', sequence_date), ('date_to', '>=', sequence_date)], limit=1)
if seq_date:
return seq_date[0]
#no date_range sequence was found, we create a new one
return self._create_date_range_seq(now)
return self._create_date_range_seq(sequence_date)
name = fields.Char(required=True)
code = fields.Char(string='Sequence Code')