account reconcile float calculation error

Bug #1158359 reported by Stephan Diehl
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Committed
Medium
OpenERP R&D Addons Team 3

Bug Description

In some constellations, the manual reconciliation has an floating point bug. so it is possible to have the same value for credit and debit but the writeoff is not zero. The bug is in this file and line:

openerp/addons/account/wizard/account_reconcile.py line 67

'writeoff': debit - credit

Original code:

return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': debit - credit}

Quick fix:

return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': round(debit - credit, 4)}

Better:

Use dp.get_precision('Account') to calculate the precision and round with this value

Still better:

Don't use float for currency calculation ;)

OpenERP Version openerp-7.0-20130225-002124

Tags: invoicing

Related branches

Revision history for this message
Amit Bhavsar (Open ERP) (amb-openerp) wrote :

Hello Stephan,

I have checked your Issue with following revision.
OE Trunk: (Build 5182)
server : 4832
addons : 8641
web : 3705

But It's working fine for me. The writeoff amount is zero while using a same amount for debit and credit. would you please check It again with latest and notify us still you have faced the same problem.

Thanks and waiting for your reply!

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Stephan Diehl (stephan-diehl-4) wrote :

The problem is described here: http://docs.python.org/2/tutorial/floatingpoint.html

Use 1762.09 for debit and credit. This was the problematic amount for me.

Revision history for this message
Amit Bhavsar (Open ERP) (amb-openerp) wrote :

Hello Stephan,

I have double check this Issue. But Still I did not faced the problem. That's why I have attached the another screen capture for your reference. would you please check It. So currently I am close this Issue. If you face the problem again than without hesitation reopen this Issue with the brief detail.

Thanks for understanding!

Changed in openobject-addons:
status: Incomplete → Invalid
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote : Re: [Bug 1158359] Re: account reconcile float calculation error

Guys, I may be wrong but I think float rounding has changed between Python
2.6 and 2.7. May be you guys can tell which Python versions you are using
for your tests?

On Fri, Mar 22, 2013 at 9:51 AM, Amit Bhavsar (Open ERP) <
<email address hidden>> wrote:

> Hello Stephan,
>
> I have double check this Issue. But Still I did not faced the problem.
> That's why I have attached the another screen capture for your
> reference. would you please check It. So currently I am close this
> Issue. If you face the problem again than without hesitation reopen this
> Issue with the brief detail.
>
> Thanks for understanding!
>
> ** Attachment added: "Reconciliation2.png"
>
> https://bugs.launchpad.net/openobject-addons/+bug/1158359/+attachment/3590224/+files/Reconciliation2.png
>
> ** Changed in: openobject-addons
> Status: Incomplete => Invalid
>
> --
> You received this bug notification because you are subscribed to OpenERP
> Addons.
> https://bugs.launchpad.net/bugs/1158359
>
> Title:
> account reconcile float calculation error
>
> Status in OpenERP Addons (modules):
> Invalid
>
> Bug description:
> In some constellations, the manual reconciliation has an floating
> point bug. so it is possible to have the same value for credit and
> debit but the writeoff is not zero. The bug is in this file and line:
>
> openerp/addons/account/wizard/account_reconcile.py line 67
>
> 'writeoff': debit - credit
>
> Original code:
>
> return {'trans_nbr': count, 'account_id': account_id, 'credit':
> credit, 'debit': debit, 'writeoff': debit - credit}
>
> Quick fix:
>
> return {'trans_nbr': count, 'account_id': account_id, 'credit':
> credit, 'debit': debit, 'writeoff': round(debit - credit, 4)}
>
> Better:
>
> Use dp.get_precision('Account') to calculate the precision and round
> with this value
>
> Still better:
>
> Don't use float for currency calculation ;)
>
> OpenERP Version openerp-7.0-20130225-002124
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/openobject-addons/+bug/1158359/+subscriptions
>

Revision history for this message
Stephan Diehl (stephan-diehl-4) wrote :

Sorry, now i have reconstructed my problematic amount.

first: we use python 2.7.3

you can test it in the python console:

python
>>> print 1762.09-1762.09
0.0
>>> print 1762.09-(1357.49+404.60)
-2.27373675443e-13

So, for the test in erp: create two invoices. one with total of 1357.49 and on of total 404.60. Then create a payment of 1762.09 and do a manual reconciliation.

Revision history for this message
Stephan Diehl (stephan-diehl-4) wrote :

see last comment

Changed in openobject-addons:
status: Invalid → New
Revision history for this message
Amit Bhavsar (Open ERP) (amb-openerp) wrote :

Hello Stephan,

I think you might have a miss understand something..
I have tested your scenario with the same value. But still I did not face any problem. also I have test in python console:
>>> print 1762.09-(1357.49+404.60)
-2.27373675443e-13
>>> print round(1762.09-(1357.49+404.60))
-0.0

So, At the both end same result. That's why I have attached the another screen capture for your reference. would you please check It and tell us still you have any doubt.

Thanks and waiting for your reply!

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Stephan Diehl (stephan-diehl-4) wrote :

Did i understand you right, that "print 1762.09-(1357.49+404.60)" in the python console gives "-2.27373675443e-13" as answer on your openerp server? with the same python version your openerp server is running on?

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Regardless of being able to reproduce the bug on certain versions of Python, Stephane is perfectly right: all float comparisons must be done with a proper precision and rounding.

The comparison happens on the view side but is based on the `writeoff` value returned by code Stephane quoted.

The values of `debit`, `credit` and `writeoff` that are returned on that line must all be properly rounded according to the 'Accounting' decimal_precision, using the float_utils.float_round() function[1].

Thanks for reporting!

[1] like it is done in other places, e.g. here: http://bazaar.launchpad.net/~openerp/openobject-addons/7.0/view/8962/account/account.py#L2127

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 3 (openerp-dev-addons3)
importance: Undecided → Medium
milestone: none → 7.0
status: Incomplete → Confirmed
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

I meant 'Stephan', not 'Stephane', sorry!

Amit Parik (amit-parik)
tags: added: invoicing
Revision history for this message
Amit Vora(OpenERP) (amit.vora-openerp) wrote :

Hello,
              I have fixed in https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-1158359-avo
              Revision ID: <email address hidden>
              Revision No:9029

Thanks,
avo.

Changed in openobject-addons:
status: Confirmed → In Progress
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.