[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 <smetl@users.noreply.github.com> Signed-off-by: wan <william-andre@users.noreply.github.com>
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user