[FIX] account: clash in resequence
Have 3 moves named 0, 1 and 2 Delete move 1 to make a hole. Resequence, starting the sequence at 2. Expected: new names are 2 and 3 Result: an error because 1 is renamed to 2 but 2 still exists, leading to a (temporary) duplicated name, which is not allowed. We clear all the names to be resequenced before doing it in order to avoid that. closes odoo/odoo#87836 X-original-commit: bf5173f64582e2675f4121122ce26cb57624e08a Signed-off-by: Quentin De Paoli <qdp@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -395,6 +395,25 @@ class TestSequenceMixin(TestSequenceMixinCommon):
|
||||
account.unlink()
|
||||
env0.cr.commit()
|
||||
|
||||
def test_resequence_clash(self):
|
||||
"""Resequence doesn't clash when it uses a name set in the same batch
|
||||
but that will be overriden later."""
|
||||
moves = self.env['account.move']
|
||||
for i in range(3):
|
||||
moves += self.create_move(name=str(i))
|
||||
moves.action_post()
|
||||
|
||||
mistake = moves[1]
|
||||
mistake.button_draft()
|
||||
mistake.posted_before = False
|
||||
mistake.with_context(force_delete=True).unlink()
|
||||
moves -= mistake
|
||||
|
||||
self.env['account.resequence.wizard'].create({
|
||||
'move_ids': moves.ids,
|
||||
'first_name': '2',
|
||||
}).resequence()
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestSequenceMixinDeletion(TestSequenceMixinCommon):
|
||||
|
||||
@@ -25,6 +25,8 @@ class ReSequenceWizard(models.TransientModel):
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
values = super(ReSequenceWizard, self).default_get(fields_list)
|
||||
if 'move_ids' not in fields_list:
|
||||
return values
|
||||
active_move_ids = self.env['account.move']
|
||||
if self.env.context['active_model'] == 'account.move' and 'active_ids' in self.env.context:
|
||||
active_move_ids = self.env['account.move'].browse(self.env.context['active_ids'])
|
||||
@@ -133,6 +135,7 @@ class ReSequenceWizard(models.TransientModel):
|
||||
if self.move_ids.journal_id and self.move_ids.journal_id.restrict_mode_hash_table:
|
||||
if self.ordering == 'date':
|
||||
raise UserError(_('You can not reorder sequence by date when the journal is locked with a hash.'))
|
||||
self.env['account.move'].browse(int(k) for k in new_values.keys()).name = False
|
||||
for move_id in self.move_ids:
|
||||
if str(move_id.id) in new_values:
|
||||
if self.ordering == 'keep':
|
||||
|
||||
Reference in New Issue
Block a user