diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 4d7eaae350f..763e6aaf28a 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2319,7 +2319,7 @@ class AccountMove(models.Model): raise UserError(_('You cannot overwrite the values ensuring the inalterability of the accounting.')) if (move.posted_before and 'journal_id' in vals and move.journal_id.id != vals['journal_id']): raise UserError(_('You cannot edit the journal of an account move if it has been posted once.')) - if (move.name and move.name != '/' and 'journal_id' in vals and move.journal_id.id != vals['journal_id']): + if (move.name and move.name != '/' and move.sequence_number not in (0, 1) and 'journal_id' in vals and move.journal_id.id != vals['journal_id']): raise UserError(_('You cannot edit the journal of an account move if it already has a sequence number assigned.')) # You can't change the date of a move being inside a locked period. diff --git a/addons/account/tests/test_sequence_mixin.py b/addons/account/tests/test_sequence_mixin.py index a42d1381811..714706e47ff 100644 --- a/addons/account/tests/test_sequence_mixin.py +++ b/addons/account/tests/test_sequence_mixin.py @@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError, UserError from odoo.tools import mute_logger from dateutil.relativedelta import relativedelta +from freezegun import freeze_time from functools import reduce import json import psycopg2 @@ -474,3 +475,17 @@ class TestSequenceMixinDeletion(TestSequenceMixinCommon): all_moves.button_draft() with self.assertRaises(UserError): all_moves.unlink() + + @freeze_time('2021-10-01 00:00:00') + def test_change_journal_on_first_account_move(self): + """Changing the journal on the first move is allowed""" + journal = self.env['account.journal'].create({ + 'name': 'awesome journal', + 'type': 'general', + 'code': 'AJ', + }) + move = self.env['account.move'].create({}) + self.assertEqual(move.name, 'MISC/2021/10/0001') + with Form(move) as move_form: + move_form.journal_id = journal + self.assertEqual(move.name, 'AJ/2021/10/0001')