From b35a5ea4a5772ea9eae46e758d75e4d0510943cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 7 Aug 2019 19:27:06 +0200 Subject: [PATCH] Increase unit price also with amount of children taxes issue7862 review251911002 --- tax.py | 13 +++++++---- tests/test_account.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/tax.py b/tax.py index fcda5afd63..3948499c94 100644 --- a/tax.py +++ b/tax.py @@ -898,15 +898,18 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): for tax in group_taxes: start_date = tax.start_date or datetime.date.min end_date = tax.end_date or datetime.date.max + values = [] if not (start_date <= date <= end_date): continue if tax.type != 'none': - value = tax._process_tax(price_unit) - res.append(value) - if tax.update_unit_price: - unit_price_variation += value['amount'] + values.append(tax._process_tax(price_unit)) if len(tax.childs): - res.extend(cls._unit_compute(tax.childs, price_unit, date)) + values.extend( + cls._unit_compute(tax.childs, price_unit, date)) + if tax.update_unit_price: + for value in values: + unit_price_variation += value['amount'] + res.extend(values) price_unit += unit_price_variation return res diff --git a/tests/test_account.py b/tests/test_account.py index a4aea87c31..de801ca928 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -883,6 +883,59 @@ class AccountTestCase(ModuleTestCase): [vat0, ecotax1, vat1, ecotax3, vat2]), Decimal(100)) + @with_transaction() + def test_tax_compute_with_children_update_unit_price(self): + "Test tax compute with children taxes modifying unit_price" + pool = Pool() + Account = pool.get('account.account') + Tax = pool.get('account.tax') + + company = create_company() + with set_company(company): + create_chart(company) + + tax_account, = Account.search([ + ('name', '=', 'Main Tax'), + ]) + + tax1 = Tax() + tax1.name = tax1.description = "Tax 1" + tax1.type = 'none' + tax1.update_unit_price = True + tax1.sequence = 1 + tax1.save() + child1 = Tax() + child1.name = child1.description = "Child 1" + child1.type = 'percentage' + child1.rate = Decimal('0.1') + child1.invoice_account = tax_account + child1.credit_note_account = tax_account + child1.parent = tax1 + child1.save() + + tax2 = Tax() + tax2.name = tax2.description = "Tax 2" + tax2.type = 'fixed' + tax2.amount = Decimal('10') + tax2.invoice_account = tax_account + tax2.credit_note_account = tax_account + tax2.sequence = 2 + tax2.save() + + self.assertEqual( + Tax.compute([tax1, tax2], Decimal(100), 2), [{ + 'base': Decimal(200), + 'amount': Decimal(20), + 'tax': child1, + }, { + 'base': Decimal('220'), + 'amount': Decimal('20'), + 'tax': tax2, + }]) + self.assertEqual( + Tax.reverse_compute(Decimal('120'), [tax1, tax2]), + Decimal('100')) + @with_transaction() def test_receivable_payable(self): 'Test party receivable payable'