Skip to content

Commit

Permalink
[FIX] account: keep the sequence consistent if canceled
Browse files Browse the repository at this point in the history
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#158665

X-original-commit: 4b5b616
Signed-off-by: Yolann Sabaux (yosa) <yosa@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
  • Loading branch information
yosa-odoo committed Mar 22, 2024
1 parent ec5059f commit cc2016c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,9 @@ def _compute_name(self):
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():
Expand Down
20 changes: 20 additions & 0 deletions addons/account/tests/test_sequence_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ def test_sequence_draft_change_date(self):
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')
Expand Down

0 comments on commit cc2016c

Please sign in to comment.