diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 044b46d68b8..9705b600e32 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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): diff --git a/odoo/addons/base/models/ir_sequence.py b/odoo/addons/base/models/ir_sequence.py index df68bee0454..67a9329c1ec 100644 --- a/odoo/addons/base/models/ir_sequence.py +++ b/odoo/addons/base/models/ir_sequence.py @@ -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')