From abc44e8027e4d3518b3de284f4773d6fbea20374 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Thu, 3 Aug 2023 07:53:00 +0000 Subject: [PATCH] [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) Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_move_line.py | 2 +- .../tests/test_account_move_out_invoice.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 24fc922bb1e..9e2f29ddf3e 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -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: diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 2963379b782..b32dd0232e8 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3647,3 +3647,25 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): self.assertEqual(invalid_invoice_2.state, 'draft') self.assertEqual(invalid_invoice_2.message_ids[0].body, "

The move could not be posted for the following reason: You need to add a line before posting.

") + + 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': []}, + ])