Skip to content

Commit

Permalink
[FIX] account: tax included
Browse files Browse the repository at this point in the history
- Create a tax included of 21 %
- Create a product sold 7.00, set the 21 % tax
- Add the product in a SO

Amount w/o tax: 5.79
Amount tax: 1.22
Total: 7.01

We defer the base rounding to the end of the method so that the rounding
doesn't impact the tax computation of included taxes.

Complement of 6e46ba7

opw-777221
  • Loading branch information
nim-odoo committed Oct 20, 2017
1 parent 3be3c6f commit c6a9bab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions addons/account/models/account.py
Expand Up @@ -758,7 +758,7 @@ def recompute_base(base_amount, fixed_amount, percent_amount):
# (145 - 15) / (1.0 + ((10 + 20) / 100.0)) = 130 / 1.3 = 100
if fixed_amount == 0.0 and percent_amount == 0.0:
return base_amount
return round((base_amount - fixed_amount) / (1.0 + percent_amount / 100.0), prec)
return (base_amount - fixed_amount) / (1.0 + percent_amount / 100.0)

base = round(price_unit * quantity, prec)

Expand Down Expand Up @@ -822,7 +822,7 @@ def recompute_base(base_amount, fixed_amount, percent_amount):
'id': tax.id,
'name': tax.with_context(**{'lang': partner.lang} if partner else {}).name,
'amount': sign * tax_amount,
'base': sign * tax_base,
'base': round(sign * tax_base, prec),
'sequence': tax.sequence,
'account_id': tax.account_id.id,
'refund_account_id': tax.refund_account_id.id,
Expand All @@ -833,7 +833,7 @@ def recompute_base(base_amount, fixed_amount, percent_amount):
'taxes': taxes_vals,
'total_excluded': sign * (currency.round(total_excluded) if round_total else total_excluded),
'total_included': sign * (currency.round(total_included) if round_total else total_included),
'base': sign * base,
'base': round(sign * base, prec),
}

@api.v7
Expand Down
21 changes: 21 additions & 0 deletions addons/account/tests/test_tax.py
Expand Up @@ -28,6 +28,12 @@ def setUp(self):
'amount': 10,
'sequence': 3,
})
self.percent_tax_bis = self.tax_model.create({
'name': "Percent tax bis",
'amount_type': 'percent',
'amount': 21,
'sequence': 3,
})
self.division_tax = self.tax_model.create({
'name': "Division tax",
'amount_type': 'division',
Expand Down Expand Up @@ -172,6 +178,21 @@ def test_tax_percent_division(self):
],
res_percent
)
self.percent_tax_bis.price_include = True
self.percent_tax_bis.include_base_amount = True
res_percent = self.percent_tax_bis.compute_all(7.0)
self._check_compute_all_results(
7.0, # 'base'
7.0, # 'total_included'
5.79, # 'total_excluded'
[
# base , amount | seq | amount | incl | incl_base
# ---------------------------------------------------
(5.79, 1.21), # | 3 | 21% | t | t
# ---------------------------------------------------
],
res_percent
)

def test_tax_sequence_normalized_set(self):
self.division_tax.sequence = 1
Expand Down

0 comments on commit c6a9bab

Please sign in to comment.