diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 1a0eca7d95fbd3f6927fc224b8db091fdc15577c..c6d48a3569c62aa9d43488d87b6a18858a0e511e 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1630,7 +1630,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(lock=False): + if not self.quick_edit_mode: self.name = '/' self._compute_name() diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index 059023d6646d58ac8ece97a7f0869a020461d845..a614444cb9b631c557a01eb60ef8ff99d5a0e225 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -1024,3 +1024,22 @@ class TestAccountMove(AccountTestInvoicingCommon): {'name': 'Purchase Tax 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') diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index d26db0aecdb83f62e3bc3806e7a032ea4f502ab3..67abca2400fd42cc1d2281570f96703a124b7c1b 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3433,3 +3433,23 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): self.assertEqual(move.currency_id, self.company_data['currency']) move.journal_id = second_journal self.assertEqual(move.currency_id, self.currency_data['currency']) + + @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')