diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f2204edb6c4..4558aaa0714 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1117,13 +1117,15 @@ class AccountMove(models.Model): # the same counter for multiple groups that might be spread in multiple months. final_batches = [] for journal_group in grouped.values(): + journal_group_changed = True for date_group in journal_group.values(): if ( - not final_batches + journal_group_changed or final_batches[-1]['format'] != date_group['format'] or dict(final_batches[-1]['format_values'], seq=0) != dict(date_group['format_values'], seq=0) ): final_batches += [date_group] + journal_group_changed = False elif date_group['reset'] == 'never': final_batches[-1]['records'] += date_group['records'] elif ( diff --git a/addons/account/tests/test_sequence_mixin.py b/addons/account/tests/test_sequence_mixin.py index ad961417acd..114deb9baa1 100644 --- a/addons/account/tests/test_sequence_mixin.py +++ b/addons/account/tests/test_sequence_mixin.py @@ -202,6 +202,24 @@ class TestSequenceMixin(AccountTestInvoicingCommon): ['J1/2010/00002', 'J0/2010/00002', 'J1/2010/00004', 'J1/2010/00003'], ) + journals[0].code = 'OLD' + journals.flush() + journal_same_code = self.env['account.journal'].create([{ + 'name': 'Journal0', + 'code': 'J0', + 'type': 'general', + }]) + moves = ( + self.create_move(date='2010-01-01', journal=journal_same_code, name='J0/2010/00001') + + self.create_move(date='2010-01-01', journal=journal_same_code) + + self.create_move(date='2010-01-01', journal=journal_same_code) + + self.create_move(date='2010-01-01', journal=journals[0]) + )._post() + self.assertEqual( + moves.mapped('name'), + ['J0/2010/00001', 'J0/2010/00002', 'J0/2010/00003', 'J0/2010/00003'], + ) + def test_journal_override_sequence_regex(self): """There is a possibility to override the regex and change the order of the paramters.""" self.create_move(date='2020-01-01', name='00000876-G 0002/2020')