diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index 7e5572aea39..829fa2d184a 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -489,8 +489,10 @@ class AccountTax(models.Model): tax_repartition_lines = (is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids).filtered(lambda x: x.repartition_type == 'tax') sum_repartition_factor = sum(tax_repartition_lines.mapped('factor')) + price_include = self._context.get('force_price_include', tax.price_include) + #compute the tax_amount - if (self._context.get('force_price_include') or tax.price_include) and total_included_checkpoints.get(i): + if price_include and total_included_checkpoints.get(i): # 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 @@ -502,7 +504,7 @@ class AccountTax(models.Model): tax_amount = round(tax_amount, prec) factorized_tax_amount = round(tax_amount * sum_repartition_factor, prec) - if tax.price_include and not total_included_checkpoints.get(i): + if price_include and not total_included_checkpoints.get(i): cumulated_tax_included_amount += factorized_tax_amount # If the tax affects the base of subsequent taxes, its tax move lines must @@ -541,7 +543,7 @@ class AccountTax(models.Model): 'sequence': tax.sequence, 'account_id': tax.cash_basis_transition_account_id.id if tax.tax_exigibility == 'on_payment' else repartition_line.account_id.id, 'analytic': tax.analytic, - 'price_include': tax.price_include or self._context.get('force_price_include'), + 'price_include': price_include, 'tax_exigibility': tax.tax_exigibility, 'tax_repartition_line_id': repartition_line.id, 'tag_ids': (repartition_line.tag_ids + subsequent_tags).ids, diff --git a/addons/account/tests/test_tax.py b/addons/account/tests/test_tax.py index d2bad20c453..142bc0c402b 100644 --- a/addons/account/tests/test_tax.py +++ b/addons/account/tests/test_tax.py @@ -66,6 +66,16 @@ class TestTaxCommon(AccountTestInvoicingCommon): (4, cls.percent_tax.id, 0) ] }) + cls.group_tax_percent = cls.env['account.tax'].create({ + 'name': "Group tax percent", + 'amount_type': 'group', + 'amount': 0, + 'sequence': 6, + 'children_tax_ids': [ + (4, cls.percent_tax.id, 0), + (4, cls.percent_tax_bis.id, 0) + ] + }) cls.group_of_group_tax = cls.env['account.tax'].create({ 'name': "Group of group tax", 'amount_type': 'group', @@ -190,6 +200,21 @@ class TestTax(TestTaxCommon): res ) + def test_tax_group_percent(self): + res = self.group_tax_percent.with_context({'force_price_include':True}).compute_all(100.0) + self._check_compute_all_results( + 100, # 'total_included' + 83.33, # 'total_excluded' + [ + # base , amount | seq | amount | incl | incl_base + # --------------------------------------------------- + (83.33, 8.33), # | 1 | 10% | | + (83.33, 8.34), # | 2 | 10% | | + # --------------------------------------------------- + ], + res + ) + def test_tax_percent_division(self): self.division_tax.price_include = True self.division_tax.include_base_amount = True