Fix reverse_compute in case there is multiple percentage taxes

issue4499
review5951002
This commit is contained in:
Nicolas Évrard
2015-01-20 09:51:04 +01:00
parent aab9dcf687
commit de8660290d
2 changed files with 49 additions and 2 deletions
+2 -2
View File
@@ -801,7 +801,7 @@ class Tax(ModelSQL, ModelView):
if rate is None:
rate = tax.rate
else:
rate *= tax.rate
rate += tax.rate
elif tax.type == 'fixed':
amount += tax.amount
@@ -811,7 +811,7 @@ class Tax(ModelSQL, ModelView):
if rate is None:
rate = child_rate
else:
rate *= child_rate
rate += child_rate
amount += child_amount
return rate, amount
+47
View File
@@ -460,6 +460,53 @@ class AccountTestCase(unittest.TestCase):
today + relativedelta(days=6)),
Decimal('100'))
ecotax1 = self.tax()
ecotax1.name = ecotax1.description = 'EcoTax 1'
ecotax1.type = 'fixed'
ecotax1.amount = Decimal(5)
ecotax1.invoice_account = tax_account
ecotax1.credit_note_account = tax_account
ecotax1.update_unit_price = True
ecotax1.sequence = 10
ecotax1.save()
vat0 = self.tax()
vat0.name = vat0.description = 'VAT0'
vat0.type = 'percentage'
vat0.rate = Decimal('0.1')
vat0.invoice_account = tax_account
vat0.credit_note_account = tax_account
vat0.sequence = 5
vat0.save()
vat1 = self.tax()
vat1.name = vat1.description = 'VAT1'
vat1.type = 'percentage'
vat1.rate = Decimal('0.2')
vat1.invoice_account = tax_account
vat1.credit_note_account = tax_account
vat1.sequence = 20
vat1.save()
self.assertEqual(
self.tax.compute([vat0, ecotax1, vat1], Decimal(100), 1),
[{
'base': Decimal(100),
'amount': Decimal(10),
'tax': vat0,
}, {
'base': Decimal(100),
'amount': Decimal(5),
'tax': ecotax1,
}, {
'base': Decimal(100),
'amount': Decimal(20),
'tax': vat1,
}])
self.assertEqual(
self.tax.reverse_compute(Decimal(135), [vat0, ecotax1, vat1]),
Decimal(100))
def suite():
suite = trytond.tests.test_tryton.suite()