[FIX] account: Disallow to post move using deprecated account.
A move in draft created with an account that is later deprecated can still be posted, while it shouldn't be allowed. Thus, we add a new error blocking this wrong behaviour. Task id #3087763 closes odoo/odoo#107354 X-original-commit: d8c2ad469299349e5184bc8986183cb205beb16a Signed-off-by: Florian Gilbert (flg) <flg@odoo.com> Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user