[FIX] account: prevent taxes on "payment_term" aml
Steps to reproduce: - Go to Contacts and open any contact (e.g. Contact X) - Check its configured Account Receivable (e.g. 121000 Account Receivable) - Configure that account and set a default Sales tax on it (e.g. Tax 15%) - Create an invoice with Contact X as customer - Add an invoice line for any amount (e.g. $100) and any tax - Swith to "Journal Items" tab and display "Taxes" column A line (with 121000 Account Receivable) has been created automatically to balance the invoice line. This line has a tax (i.e. Tax 15%): the default one configured on the account. There should not be a tax for a receivable account. Another issue is that the tax is set on the aml but not tax line has been created. - Go back to "Invoice Lines" tab - Remove the tax on the invoice line - Save In "Journal Items" tab, the tax line has been created from the aml with the receivable account. - Go back to "Invoice Lines" tab - Add a tax on the invoice line again - Save - Remove the tax on the invoice line - Save In "Journal Items" tab, there are now 2 tax lines from the aml with the receivable account. By repeating the previous steps, new tax lines can be created infinitely. Solution: To prevent the issue, the default taxes shouldn't be populated on the aml when the account is a receivable (or payable) one and when the move type is an "invoice" type one. As "display_type" field of "account.move.line" is set to "payment_term" when the account is a receivable or a payable one and when "is_invoice" is True on the move, no tax will be set in "_compute_tax_ids" computed method when "display_type" is "payment_term". opw-3345953 closes odoo/odoo#131330 X-original-commit: c6076a272cfe997856f3026557900ce9718c45e5 Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com> Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
@@ -843,7 +843,7 @@ class AccountMoveLine(models.Model):
|
||||
@api.depends('product_id', 'product_uom_id')
|
||||
def _compute_tax_ids(self):
|
||||
for line in self:
|
||||
if line.display_type in ('line_section', 'line_note'):
|
||||
if line.display_type in ('line_section', 'line_note', 'payment_term'):
|
||||
continue
|
||||
# /!\ Don't remove existing taxes if there is no explicit taxes set on the account.
|
||||
if line.product_id or line.account_id.tax_ids or not line.tax_ids:
|
||||
|
||||
@@ -3647,3 +3647,25 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
self.assertEqual(invalid_invoice_2.state, 'draft')
|
||||
self.assertEqual(invalid_invoice_2.message_ids[0].body,
|
||||
"<p>The move could not be posted for the following reason: You need to add a line before posting.</p>")
|
||||
|
||||
def test_no_taxes_on_payment_term_line(self):
|
||||
''' No tax should be set on payment_term lines'''
|
||||
|
||||
receivable_account = self.partner_a.property_account_receivable_id
|
||||
receivable_account.tax_ids = [Command.set(self.company_data['default_tax_sale'].ids)]
|
||||
|
||||
invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner_a.id,
|
||||
'invoice_line_ids': [
|
||||
Command.create({
|
||||
'name': 'test line',
|
||||
'quantity': 1,
|
||||
'price_unit': 100,
|
||||
})
|
||||
],
|
||||
})
|
||||
|
||||
self.assertRecordValues(invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term'), [
|
||||
{'account_id': receivable_account.id, 'tax_ids': []},
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user