From cee75c14a19fd7c08c9c5b33ab4d682b123283f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 15 Mar 2024 13:16:33 +0100 Subject: [PATCH] Do not distribute residual rounding to tax with 0 amount Closes #13098 --- modules/account/tax.py | 9 +++-- modules/account/tests/test_module.py | 58 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/modules/account/tax.py b/modules/account/tax.py index 3f31fa7086..3c405a49ac 100644 --- a/modules/account/tax.py +++ b/modules/account/tax.py @@ -1263,10 +1263,11 @@ class TaxableMixin(object): offset_amount = self.currency.rounding.copy_sign(remainder) for tax in cycle(taxes.values()): - tax['amount'] -= offset_amount - remainder -= offset_amount - if abs(remainder) < self.currency.rounding: - break + if tax['amount']: + tax['amount'] -= offset_amount + remainder -= offset_amount + if abs(remainder) < self.currency.rounding: + break @fields.depends('company', methods=['_get_tax_context', '_round_taxes']) def _get_taxes(self): diff --git a/modules/account/tests/test_module.py b/modules/account/tests/test_module.py index 62373a2c89..3a1850d926 100644 --- a/modules/account/tests/test_module.py +++ b/modules/account/tests/test_module.py @@ -1278,6 +1278,64 @@ class AccountTestCase( self.assertEqual(taxline_2['base'], Decimal('1.04')) self.assertEqual(taxline_2['amount'], Decimal('.10')) + @with_transaction() + def test_taxable_mixin_tax_residual_rounding_with_0(self): + "Test TaxableMixin for rounding with residual amount and tax 0" + pool = Pool() + Account = pool.get('account.account') + Tax = pool.get('account.tax') + Configuration = pool.get('account.configuration') + currency = create_currency('cur') + + company = create_company() + with set_company(company): + create_chart(company) + + config = Configuration(1) + config.tax_rounding = 'line' + config.save() + + tax_account, = Account.search([ + ('name', '=', 'Main Tax'), + ]) + + tax0 = Tax() + tax0.name = tax0.description = "Tax 0" + tax0.type = 'percentage' + tax0.rate = Decimal('0') + tax0.invoice_account = tax_account + tax0.credit_note_account = tax_account + tax0.save() + tax1 = Tax() + tax1.name = tax1.description = "Tax 1" + tax1.type = 'percentage' + tax1.rate = Decimal('.1') + tax1.invoice_account = tax_account + tax1.credit_note_account = tax_account + tax1.save() + tax2 = Tax() + tax2.name = tax2.description = "Tax 2" + tax2.type = 'percentage' + tax2.rate = Decimal('.1') + tax2.invoice_account = tax_account + tax2.credit_note_account = tax_account + tax2.save() + + taxable = self.Taxable( + currency=currency, + taxable_lines=[ + ([tax0, tax1, tax2], Decimal('1.0417'), 1, None), + ], + company=company) + + taxline_0, taxline_1, taxline_2 = taxable._get_taxes() + self.assertEqual(taxline_0['base'], Decimal('1.04')) + self.assertEqual(taxline_0['amount'], Decimal('0')) + self.assertEqual(taxline_1['base'], Decimal('1.04')) + self.assertEqual(taxline_1['amount'], Decimal('.11')) + self.assertEqual(taxline_2['base'], Decimal('1.04')) + self.assertEqual(taxline_2['amount'], Decimal('.10')) + @with_transaction() def test_taxable_mixin_tax_residual_rounding_negative_residual(self): "Test TaxableMixin for rounding with negative residual amount"