[FIX] account: fix resequence triggers unique constraint

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) <wan@odoo.com>
Signed-off-by: Julien Alardot (jual) <jual@odoo.com>
This commit is contained in:
Julien Alardot (jual)
2023-04-22 06:53:55 +02:00
parent 1fddf0d02d
commit ca0fabca1c
+5 -1
View File
@@ -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':