From a7f855f78943f18244f39d3f3f21d526eaaf0e00 Mon Sep 17 00:00:00 2001 From: "Walid HANNICHE (waha)" Date: Thu, 15 Dec 2022 09:31:52 +0000 Subject: [PATCH] [FIX] account: tax included in subsequent taxes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: 1. Create a new tax (TAX1) with a lower sequence than VAT(15%). 2. Check Affect Base of subsequent taxes. 3. Create an invoice, add a line with a product and both taxes. 4. Remove the invoice line. 5. Check Journal Items tab: a VAT line is still there with an amount Bug: When we create an invoice line with (affecting + affected) taxes, 4 Journal items are created, including the affecting tax line having the affected tax as tax id. When we remove the invoice line, the system sync the dynamic lines, recomputing all the taxes to check what to create/write/delete As one of the tax entries has a tax it will be left as a needed line while it should be removed. FIX: avoid computing `_compute_all_tax` for tax lines closes odoo/odoo#108048 X-original-commit: 4fbd639965107fc9363dddb553a70461cd596c0c Signed-off-by: William André (wan) Signed-off-by: Walid Hanniche (waha) --- addons/account/models/account_move_line.py | 6 ++- .../test_account_move_line_tax_details.py | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 9760d5f8787..8f5c5a80d00 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -918,14 +918,16 @@ class AccountMoveLine(models.Model): def _compute_all_tax(self): for line in self: sign = line.move_id.direction_sign + if line.display_type == 'tax': + line.compute_all_tax = {} + line.compute_all_tax_dirty = False + continue if line.display_type == 'product' and line.move_id.is_invoice(True): amount_currency = sign * line.price_unit * (1 - line.discount / 100) - amount = sign * line.price_unit / line.currency_rate * (1 - line.discount / 100) handle_price_include = True quantity = line.quantity else: amount_currency = line.amount_currency - amount = line.balance handle_price_include = False quantity = 1 compute_all_currency = line.tax_ids.compute_all( diff --git a/addons/account/tests/test_account_move_line_tax_details.py b/addons/account/tests/test_account_move_line_tax_details.py index 752cb3344a1..167b54cf2d3 100644 --- a/addons/account/tests/test_account_move_line_tax_details.py +++ b/addons/account/tests/test_account_move_line_tax_details.py @@ -540,6 +540,46 @@ class TestAccountTaxDetailsReport(AccountTestInvoicingCommon): ) self.assertTotalAmounts(invoice, tax_details) + def test_affect_base_amount_6(self): + affecting_tax = self.env['account.tax'].create({ + 'name': 'Affecting', + 'amount': 42, + 'amount_type': 'percent', + 'type_tax_use': 'sale', + 'include_base_amount': True, + 'sequence': 0, + }) + + affected_tax = self.env['account.tax'].create({ + 'name': 'Affected', + 'amount': 10, + 'amount_type': 'percent', + 'type_tax_use': 'sale', + 'sequence': 1 + }) + + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2021-08-01', + 'invoice_line_ids': [ + Command.create({ + 'name': "affecting + affected", + 'account_id': self.company_data['default_account_revenue'].id, + 'quantity': 1.0, + 'price_unit': 100.0, + 'tax_ids': (affecting_tax + affected_tax).ids, + }), + ] + }) + + invoice.write({'invoice_line_ids': [Command.delete(invoice.invoice_line_ids.id)]}) + base_lines, tax_lines = self._dispatch_move_lines(invoice) + self.assertFalse(base_lines) + self.assertFalse(tax_lines) + tax_details = self._get_tax_details() + self.assertFalse(tax_details) + def test_round_globally_rounding(self): self.env.company.tax_calculation_rounding_method = 'round_globally'