From e66efe8fe0da41c6bfc59d7cad80ef4ca1ae012a Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Fri, 3 Jun 2022 11:55:33 +0000 Subject: [PATCH] [FIX] account: properly handle move without sequence_number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since Odoo v15, user can rename invoice to a custom value. Odoo automatically detects `sequence_number` for the new name. If no number is detected, the `sequence_number` is set to zero. In this edge case, method `_is_end_of_seq_chain` doesn't work and raises an exception, because `last_rec` is empty, while `_get_last_sequence` has constrain `self.ensure_one()`. Fix it by allowing `last_rec` with zero `sequence_number`. STEPS: * Create invoice * Confirm * Reset to Draft * Rename invoice to "Test" * Save * Try to delete the invoice BEFORE: ensure_one error Once it's fixed, we face another problem: User Error *You cannot delete this entry, as it has already consumed a sequence number and is not the last one in the chain. You should probably revert it instead.* It happens because `sequence_prefix` is computed as empty string, while `_get_last_sequence` method ignores empty values. Fix it by allowing search by empty string too. AFTER the two changes user can delete draft invoice opw-2861841 closes odoo/odoo#95614 X-original-commit: 301b499b9d0ce189dc5d0433e55ce654d212927b Signed-off-by: William André (wan) --- addons/account/models/sequence_mixin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/sequence_mixin.py b/addons/account/models/sequence_mixin.py index 7adf8491cb0..c2d671b3f95 100644 --- a/addons/account/models/sequence_mixin.py +++ b/addons/account/models/sequence_mixin.py @@ -161,7 +161,7 @@ class SequenceMixin(models.AbstractModel): if self.id or self.id.origin: where_string += " AND id != %(id)s " param['id'] = self.id or self.id.origin - if with_prefix: + if with_prefix is not None: where_string += " AND sequence_prefix = %(with_prefix)s " param['with_prefix'] = with_prefix @@ -270,7 +270,7 @@ class SequenceMixin(models.AbstractModel): seq = format_values.pop('seq') batch = batched[(seq_format, frozendict(format_values))] batch['seq_list'].append(seq) - if batch['last_rec'].sequence_number < record.sequence_number: + if batch['last_rec'].sequence_number <= record.sequence_number: batch['last_rec'] = record for values in batched.values():