From 75d4ffc83b88814503bb8749cd1387770df16137 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 3 Aug 2020 08:13:10 +0000 Subject: [PATCH] [FIX] account: update the sequence when we change the date The first Journal Entry of a tuple (period, journal) has a name set by default so that the user can change it before posting. If we changed the date after the name has been given, it never changed anymore; meaning the number could not be of the same period as the date of the Journal Entry. We now always reset the name to the default one if the name has to be recomputed (change of date/journal) closes odoo/odoo#55321 X-original-commit: 0c5d71aab8eefb57116a5b93b4c67222a080ddec Signed-off-by: Laurent Smet Signed-off-by: wan --- addons/account/models/account_move.py | 8 +++---- .../account/tests/test_account_move_entry.py | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index ab23a2678c9..79da861439b 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1037,16 +1037,16 @@ class AccountMove(models.Model): @api.depends('posted_before', 'state', 'highest_name') def _compute_name(self): for record in self.sorted(lambda m: (m.date, m.ref or '', m.id)): + if record.name and not record.posted_before: + # Never been posted, but had a name set + record.name = '/' if not record.name or record.name == '/': - if record.state == 'draft' and not record.posted_before and not record.highest_name: + if not record.posted_before and not record.highest_name: # First name of the period for the journal, no name yet record._set_next_sequence() elif record.state == 'posted': # No name yet but has been posted record._set_next_sequence() - if record.name and record.state == 'draft' and not record.posted_before and record.highest_name: - # Not the first name of the period for the journal, but had a name set - record.name = '/' record.name = record.name or '/' @api.depends('journal_id', 'date') diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index 554ad39fec1..61bbd3dee9e 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -340,6 +340,27 @@ class TestAccountMove(AccountTestInvoicingCommon): # You can remove journal items if the related journal entry is still balanced. self.test_move.line_ids.unlink() + def test_sequence_change_date(self): + # Check setup + self.assertEqual(self.test_move.state, 'draft') + self.assertEqual(self.test_move.name, 'MISC/2016/01/0001') + self.assertEqual(fields.Date.to_string(self.test_move.date), '2016-01-01') + + # Never posetd, the number must change if we change the date + self.test_move.date = '2020-02-02' + self.assertEqual(self.test_move.name, 'MISC/2020/02/0001') + + # We don't recompute user's input when posting + self.test_move.name = 'MyMISC/2020/0000001' + self.test_move.post() + self.assertEqual(self.test_move.name, 'MyMISC/2020/0000001') + + # Has been posted, and it doesn't change anymore + self.test_move.button_draft() + self.test_move.date = '2020-01-02' + self.test_move.post() + self.assertEqual(self.test_move.name, 'MyMISC/2020/0000001') + def test_journal_sequence(self): self.assertEqual(self.test_move.name, 'MISC/2016/01/0001') self.test_move.post()