From 747d4da69bd87cd95df733e5c385d3da751d76b9 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Tue, 21 Dec 2021 11:45:54 +0000 Subject: [PATCH] [FIX] account: don't mistake a tax with a sum of tax repartition factors == 0 for a 0% tax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consider this example: - Create a 42% tax, price-included, with two tax repartition lines doing +100 -100 - Create an invoice of 100€ using this tax, and look at the move lines generated ==> Only a base line of 100 and a receivable/payable line of 100 have been created; no tax line. This is wrong, as we'd expect to see: - 100 in payable/receivable - 100 for the base line - 42 for the +100 tax repartition line - -42 for the -100 tax repartition line The two tax lines are missing because the compute_all considers the tax as a 0% one, because of the +100 -100 stuff. OPW 2716083 closes odoo/odoo#81771 X-original-commit: 9d24e3cf002bacb09d6e955b26124dda09c15f18 Signed-off-by: Laurent Smet Signed-off-by: Olivier Colson --- addons/account/models/account_tax.py | 2 +- addons/account/tests/test_tax.py | 58 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index 47806b952d6..2f8389069d6 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -568,7 +568,7 @@ class AccountTax(models.Model): sum_repartition_factor = sum(tax_repartition_lines.mapped('factor')) #compute the tax_amount - if not skip_checkpoint and price_include and total_included_checkpoints.get(i): + if not skip_checkpoint and price_include and total_included_checkpoints.get(i) and sum_repartition_factor != 0: # We know the total to reach for that tax, so we make a substraction to avoid any rounding issues tax_amount = total_included_checkpoints[i] - (base + cumulated_tax_included_amount) cumulated_tax_included_amount = 0 diff --git a/addons/account/tests/test_tax.py b/addons/account/tests/test_tax.py index cbe043ada69..e9b769c0ffe 100644 --- a/addons/account/tests/test_tax.py +++ b/addons/account/tests/test_tax.py @@ -1109,3 +1109,61 @@ class TestTax(TestTaxCommon): ], (tax_10_fix + tax_21).compute_all(1210), ) + + def test_price_included_repartition_sum_0(self): + """ Tests the case where a tax with a non-zero value has a sum + of tax repartition factors of zero and is included in price. It + shouldn't behave in the same way as a 0% tax. + """ + test_tax = self.env['account.tax'].create({ + 'name': "Definitely not a 0% tax", + 'amount_type': 'percent', + 'amount': 42, + 'price_include': True, + 'invoice_repartition_line_ids': [ + (0, 0, { + 'factor_percent': 100, + 'repartition_type': 'base', + }), + + (0, 0, { + 'factor_percent': 100, + 'repartition_type': 'tax', + }), + + (0, 0, { + 'factor_percent': -100, + 'repartition_type': 'tax', + }), + ], + 'refund_repartition_line_ids': [ + (0, 0, { + 'factor_percent': 100, + 'repartition_type': 'base', + }), + + (0, 0, { + 'factor_percent': 100, + 'repartition_type': 'tax', + }), + + (0, 0, { + 'factor_percent': -100, + 'repartition_type': 'tax', + }), + ], + }) + + compute_all_res = test_tax.compute_all(100) + self._check_compute_all_results( + 100, # 'total_included' + 100, # 'total_excluded' + [ + # base , amount + # --------------- + (100, 42), + (100, -42), + # --------------- + ], + compute_all_res + )