[FIX] account: prevent unnecessary recompute of invoice line account_id
Summary ------ Currently, when removing a product from an invoice line, the account for that invoice line is automatically reset to a default value. Steps to reproduce ------------------ * install `account_accountant` * create an invoice and add a product * set a different account on that invoice line * remove the product from the line You should see that the account is automatically changed. opw-3092556 closes odoo/odoo#139361 X-original-commit: 39b44dbfef0d533722ce2c96d375ada113d32b00 Signed-off-by: de Wouters de Bouchout Jean-Benoît (jbw) <jbw@odoo.com> Signed-off-by: Séna Serge Nshimiyimana (sesn) <sesn@odoo.com>
This commit is contained in:
@@ -1135,6 +1135,7 @@ class AccountMoveLine(models.Model):
|
||||
@api.onchange('product_id')
|
||||
def _inverse_product_id(self):
|
||||
self._conditional_add_to_compute('account_id', lambda line: (
|
||||
(self.product_id or not self.account_id) and
|
||||
line.display_type == 'product' and line.move_id.is_invoice(True)
|
||||
))
|
||||
|
||||
|
||||
@@ -3771,3 +3771,26 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
duplicate_invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term').account_id,
|
||||
other_receivable_account
|
||||
)
|
||||
|
||||
def test_account_on_invoice_line_product_removal(self):
|
||||
"""Removing a product from an invoice line should preserve that line's account."""
|
||||
other_income_account = self.product_a.property_account_income_id.copy()
|
||||
|
||||
invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner_a.id,
|
||||
'invoice_date': fields.Date.from_string('2019-01-01'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({
|
||||
'product_id': self.product_a.id,
|
||||
}),
|
||||
]
|
||||
})
|
||||
invoice.invoice_line_ids.account_id = other_income_account
|
||||
invoice.invoice_line_ids.product_id = False
|
||||
|
||||
self.assertEqual(
|
||||
invoice.invoice_line_ids.account_id,
|
||||
other_income_account,
|
||||
"Removing a product from an invoice line should no change the account."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user