[FIX] account: change journal on draft invoice
Step to reproduce: - Create a SO, save and confirm it - Create an invoice, on edit mode, change the journal and click on save Issue: - If the invoice is the first one in the current month, a sequence number is automatically assigned and an error is displaid. forwardport of https://github.com/odoo/odoo/commit/b8328e45d526d276b5781da3523a0d5874da64bd opw-2660571 opw-2879716 closes odoo/odoo#79084 closes odoo/odoo#95386 X-original-commit: 7b296982139518460405fa63eca6774bd82ba7b1 Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Minet Adrien (admi) <admi@odoo.com>
This commit is contained in:
committed by
Adrien Minet
parent
e96757194c
commit
4805103274
@@ -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.
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user