[FIX] account: change journal on journal entry
With this commit, we make sure that the name
of an entry is well computed when changing
the journal in the form view.
Steps:
- With fresh db
- Open a new journal entry form
- Change the journal
-> The name doesn't change, it should change
regarding the code of the journal
Also add a test for the fix which introduced
the issue 46e6ae2941.
opw-3332590
closes odoo/odoo#123724
X-original-commit: 29d59960f7c19a7adda094d1effad6ba5f68f918
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
Signed-off-by: Guillaume Vanleynseele (guva) <guva@odoo.com>
This commit is contained in:
@@ -1706,7 +1706,7 @@ class AccountMove(models.Model):
|
||||
|
||||
@api.onchange('journal_id')
|
||||
def _onchange_journal_id(self):
|
||||
if not self.quick_edit_mode and self._get_last_sequence():
|
||||
if not self.quick_edit_mode:
|
||||
self.name = '/'
|
||||
self._compute_name()
|
||||
|
||||
|
||||
@@ -1022,3 +1022,22 @@ class TestAccountMove(AccountTestInvoicingCommon):
|
||||
{'name': '15%', 'credit': 0.0, 'debit': 15.0, 'account_id': self.company_data['default_account_tax_purchase'].id, 'tax_ids': [], 'tax_base_amount': 100, 'tax_tag_invert': False, 'tax_repartition_line_id': purchase_invoice_rep_line.id},
|
||||
{'name': 'debit', 'credit': 0.0, 'debit': 100.0, 'account_id': test_account.id, 'tax_ids': purchase_tax.ids, 'tax_base_amount': 0, 'tax_tag_invert': False, 'tax_repartition_line_id': False},
|
||||
])
|
||||
|
||||
@freeze_time('2021-10-01 00:00:00')
|
||||
def test_change_journal_account_move(self):
|
||||
"""Changing the journal should change the name of the move"""
|
||||
journal = self.env['account.journal'].create({
|
||||
'name': 'awesome journal',
|
||||
'type': 'general',
|
||||
'code': 'AJ',
|
||||
})
|
||||
move = self.env['account.move'].with_context(default_move_type='entry')
|
||||
with Form(move) as move_form:
|
||||
self.assertEqual(move_form.name, 'MISC/2021/10/0001')
|
||||
move_form.journal_id, journal = journal, move_form.journal_id
|
||||
self.assertEqual(move_form.name, 'AJ/2021/10/0001')
|
||||
# ensure we aren't burning any sequence by switching journal
|
||||
move_form.journal_id, journal = journal, move_form.journal_id
|
||||
self.assertEqual(move_form.name, 'MISC/2021/10/0001')
|
||||
move_form.journal_id, journal = journal, move_form.journal_id
|
||||
self.assertEqual(move_form.name, 'AJ/2021/10/0001')
|
||||
|
||||
@@ -3453,3 +3453,23 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
|
||||
# Date of the reversal of the exchange move should be the last day of the month/year of the payment depending on the sequence format
|
||||
self.assertEqual(exchange_move_reversal.date, fields.Date.to_date(expected_date))
|
||||
|
||||
@freeze_time('2023-01-01')
|
||||
def test_change_first_journal_move_sequence(self):
|
||||
"""Invoice name should not be reset when posting the invoice"""
|
||||
new_sale_journal = self.company_data['default_journal_sale'].copy()
|
||||
invoice = self.env['account.move'].with_context(default_move_type='out_invoice').create({
|
||||
'journal_id': new_sale_journal.id,
|
||||
'partner_id': self.partner_a.id,
|
||||
'name': 'INV1/2023/00010',
|
||||
'invoice_line_ids': [
|
||||
Command.create({
|
||||
'name': 'My super product.',
|
||||
'quantity': 1.0,
|
||||
'price_unit': 750.0,
|
||||
'account_id': self.company_data['default_account_revenue'].id,
|
||||
})
|
||||
]
|
||||
})
|
||||
invoice.action_post()
|
||||
self.assertEqual(invoice.name, 'INV1/2023/00010')
|
||||
|
||||
Reference in New Issue
Block a user