!!critical bug when rounding taxes in invoices!! -> urgent patch otherwise accounting and invoices can be wrong; possible patch included
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Odoo Addons (MOVED TO GITHUB) |
Invalid
|
Critical
|
Unassigned |
Bug Description
Hi,
This bug sounds critical. We just saw this in prod comparing supplier invoices with OpenERP invoices.
The thing is that it seems that the total tax amount per invoice (in a tax category eg tax line) result of the sum of the taxes of that category for each invoice line.
But, instead of rounding AFTER summing the invoice lines, OpenERP first rounds at two digits at each invoice line and then sums that into a tax total for that category of taxes. So sometimes rounding errors propagate themselves from lines to lines and the tax total is simply wrong: it multiply the approximation per line by the number of invoice lines. It can easily be 5 cents wrong and 5 cents sucks in accounting (accounting along sucks, so for 5 cents, you can imagine how much it sucks). Accountants tend to be psyco-rigid frustrated people that will bug for 5 cents you know...
The error is reproducible each time you click on the 'Compute Taxes' button in an invoice. That call the account.
for line in inv.invoice_line:
for tax in tax_obj.compute(cr, uid, line.invoice_
This is where it's wrong already. Going further in the stack brings us to account.tax#compute
And in that method, OpenERP is rounding at two digit with code like:
round(r['amount'] * quantity, 2)
In our production v5 OpenERP, we replaced that 2 by a 5 and got all tax amount done right. Since we preferred to be too careful, we also use 5 digit rounding for the balance field here, see attached patch.
I'm not saying this is the right fix, you are very much welcome to think about it before applying the patch, but it might be much closer to the right thing than the current implementation. Obviously, the more lines in the invoice, the more precision digit you need for each line before summing. 5 digit seems to guarantee it will work over 100 invoice lines. May be OpenERP needs to opt for even more precision. Also bare in mind that all that rounding thing (like 2 digits hardcoded) will probably not work for some currencies requiring more precision, but that's an other story.
The more invoice lines you have, the more risk you take with the current implementation. Luckily, once the patch is applied, you only need to iterate each invoice and click on the "compute taxes" button to get it fixed. But that won't fix the invoices you already sent to your customers... That's why I suggest Tiny communicate around that one and tell the community to apply that patch (or similar) quickly.
Hope this helps,
Raphaël Valyi.
hop this helps.
Changed in openobject-addons: | |
importance: | Undecided → Critical |
hello,
we agree on the critical dimension of this bug: the compute method should NOT do the rounding this way... It shouldn't round the float at all.
Another point for you: rounding on 2 digits is completely arbitrary and doesn't take in consideration the currency rounding factor.
Since this mod needs a in depth testing and a revision of several modules, we cannot afford to release a patch immediately. It should be available in a few days.
Thanks for the bug report