diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 2b398505ae6..f0a6b319a04 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -1104,6 +1104,13 @@ msgstr "" msgid "A line cannot have both children and a groupby value (line '%s')." msgstr "" +#. module: account +#: code:addons/account/models/account_move.py:0 +#, python-format +msgid "" +"A line of this move is using a deprecated account, you cannot post it." +msgstr "" + #. module: account #: code:addons/account/models/account_payment.py:0 #, python-format diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index d13a23d2862..0d7d1424290 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3270,6 +3270,9 @@ class AccountMove(models.Model): move.currency_id.name )) + if move.line_ids.account_id.filtered(lambda account: account.deprecated): + raise UserError(_("A line of this move is using a deprecated account, you cannot post it.")) + affects_tax_report = move._affect_tax_report() lock_dates = move._get_violated_lock_dates(move.date, affects_tax_report) if lock_dates: diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 1ca34354b2c..61879d19b29 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3333,3 +3333,22 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): self.assertEqual(invoice.amount_untaxed, 82.64) self.assertEqual(invoice.amount_tax, 17.36) self.assertEqual(len(invoice.invoice_line_ids), 2) + + def test_out_invoice_depreciated_account(self): + move = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'currency_id': self.currency_data['currency'].id, + 'partner_id': self.partner_a.id, + 'journal_id': self.company_data['default_journal_sale'].id, + 'invoice_line_ids': [ + (0, 0, { + 'name': 'My super product.', + 'quantity': 1.0, + 'price_unit': 750.0, + 'account_id': self.product_a.property_account_income_id.id, + }) + ], + }) + self.product_a.property_account_income_id.deprecated = True + with self.assertRaises(UserError), self.cr.savepoint(): + move.action_post()