[FIX] account: keep the sequence consistent if canceled
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) <yosa@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user