[FIX] account: same sequence in different journal clash

When the same sequence is used in different journals (i.e. BNK1 in two
different companies), a clash might happen in the grouping optimization
of the `_compute_name`

closes odoo/odoo#70152

Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
wan
2021-05-04 07:45:03 +00:00
parent 5b5e6943eb
commit efc407cacd
2 changed files with 21 additions and 1 deletions
+3 -1
View File
@@ -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 (
@@ -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')