diff --git a/addons/account/tests/test_sequence_mixin.py b/addons/account/tests/test_sequence_mixin.py index a52c7981bbe..c6ef82b6eca 100644 --- a/addons/account/tests/test_sequence_mixin.py +++ b/addons/account/tests/test_sequence_mixin.py @@ -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): diff --git a/addons/account/wizard/account_resequence.py b/addons/account/wizard/account_resequence.py index a8d7c18a0dc..2267857af5d 100644 --- a/addons/account/wizard/account_resequence.py +++ b/addons/account/wizard/account_resequence.py @@ -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':