From cc2016c4e99f32341a4c266beacd18a184d5a638 Mon Sep 17 00:00:00 2001 From: yosa-odoo Date: Thu, 7 Mar 2024 09:15:45 +0000 Subject: [PATCH] [FIX] account: keep the sequence consistent if canceled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: ``` | Step | Move | Action | Date | Name | | ---- | ---- | ----------- | ---------- | ----------- | | 1 | `A` | Add | 2023-02-01 | `2023/02/0001` | | 2 | `B` | Add | 2023-02-02 | `/` | | 3 | `B` | Post | 2023-02-02 | `2023/02/0002` | | 4 | `A` | Cancel | 2023-02-01 | `2023/02/0003` | -> Wrong ``` Issue: The first invoice should keep its sequence to 1 opw-3757022 closes odoo/odoo#158665 X-original-commit: 4b5b6162707bc692f12295cd116c363d5eb32a57 Signed-off-by: Yolann Sabaux (yosa) Signed-off-by: William André (wan) --- addons/account/models/account_move.py | 3 +++ addons/account/tests/test_sequence_mixin.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 42adfd42eb7..2329c551de6 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -755,6 +755,9 @@ class AccountMove(models.Model): self = self.sorted(lambda m: (m.date, m.ref or '', m._origin.id)) for move in self: + if move.state == 'cancel': + continue + move_has_name = move.name and move.name != '/' if move_has_name or move.state != 'posted': if not move.posted_before and not move._sequence_matches_date(): diff --git a/addons/account/tests/test_sequence_mixin.py b/addons/account/tests/test_sequence_mixin.py index 42d81ab7a6c..2f642d91973 100644 --- a/addons/account/tests/test_sequence_mixin.py +++ b/addons/account/tests/test_sequence_mixin.py @@ -226,6 +226,26 @@ class TestSequenceMixin(TestSequenceMixinCommon): self.assertEqual(new_multiple_move_1.name, 'AJ/2016/01/0001') move_form.date = fields.Date.to_date('2016-01-10') + def test_sequence_draft_first_of_period(self): + """ + | Step | Move | Action | Date | Name | + | ---- | ---- | ----------- | ---------- | ----------- | + | 1 | `A` | Add | 2023-02-01 | `2023/02/0001` | + | 2 | `B` | Add | 2023-02-02 | `/` | + | 3 | `B` | Post | 2023-02-02 | `2023/02/0002` | + | 4 | `A` | Cancel | 2023-02-01 | `2023/02/0001` | -> Assert + """ + move_a = self.test_move.copy({'date': '2023-02-01'}) + self.assertEqual(move_a.name, 'MISC/2023/02/0001') + + move_b = self.test_move.copy({'date': '2023-02-02'}) + self.assertEqual(move_b.name, '/') + + move_b.action_post() + self.assertEqual(move_b.name, 'MISC/2023/02/0002') + + move_a.button_cancel() + self.assertEqual(move_a.name, 'MISC/2023/02/0001') def test_journal_sequence(self): self.assertEqual(self.test_move.name, 'MISC/2016/01/0001')