[FIX] account: avoid rounding issues when using a tax with multiple repartition lines

- create an invoice with only one line with a price of 91.56
- assign a tax of 15% using two 50% repartition lines to this invoice line

==> The total tax amount computed was 13.74; it should be 13.73.

closes odoo/odoo#35412

Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Olivier Colson
2019-08-02 13:50:35 +00:00
committed by Laurent Smet
parent fd0813d506
commit 5bacf72319
+3 -3
View File
@@ -1426,12 +1426,12 @@ class AccountTax(models.Model):
subsequent_tags = subsequent_taxes.get_tax_tags(is_refund, 'base')
# Compute the tax lines
tax_repartition_lines = is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids
tax_repartition_lines = (is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids).filtered(lambda x: x.repartition_type == 'tax')
repartition_lines_to_treat = len(tax_repartition_lines)
total_amount = 0
for repartition_line in tax_repartition_lines.filtered(lambda x: x.repartition_type == 'tax'):
for repartition_line in tax_repartition_lines:
# In case some rounding error occurs, we compensate for it on the last line
line_amount = round(sign * tax_amount * repartition_line.factor if repartition_lines_to_treat != 1 else tax_amount - total_amount, prec)
line_amount = round(sign * tax_amount * repartition_line.factor if repartition_lines_to_treat != 1 else sign * (tax_amount - total_amount), prec)
taxes_vals.append({
'id': tax.id,