From ca0fabca1ce74f457f876ef93a18d8682a2fe2a3 Mon Sep 17 00:00:00 2001 From: "Julien Alardot (jual)" Date: Thu, 20 Apr 2023 11:54:25 +0000 Subject: [PATCH] [FIX] account: fix resequence triggers unique constraint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the resequencing, if an account.move new name correspond to an old name, it could trigger the unique constraint ValidationError. This temporarily rename the concerned moves to avoid triggering the constraint Task-3280680 closes odoo/odoo#119427 X-original-commit: 18d73e235908b63534105434c78b3a637b827e10 Signed-off-by: William André (wan) Signed-off-by: Julien Alardot (jual) --- addons/account/wizard/account_resequence.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/account/wizard/account_resequence.py b/addons/account/wizard/account_resequence.py index a3d60d37f06..2e5016b25bb 100644 --- a/addons/account/wizard/account_resequence.py +++ b/addons/account/wizard/account_resequence.py @@ -138,7 +138,11 @@ 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 + moves_to_rename = self.env['account.move'].browse(int(k) for k in new_values.keys()) + moves_to_rename.name = '/' + moves_to_rename.flush_recordset(["name"]) + # If the db is not forcibly updated, the temporary renaming could only happen in cache and still trigger the constraint + for move_id in self.move_ids: if str(move_id.id) in new_values: if self.ordering == 'keep':