Merge lp:~openerp-dev/openobject-server/6.0-opw-18123-Lorenzo_Battistini into lp:openobject-server/6.0

Proposed by Amit Dodiya (OpenERP)
Status: Rejected
Rejected by: Xavier ALT
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-18123-Lorenzo_Battistini
Merge into: lp:openobject-server/6.0
Diff against target: 20 lines (+2/-1)
1 file modified
bin/addons/base/res/res_currency.py (+2/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-18123-Lorenzo_Battistini
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Disapprove
Lorenzo Battistini (community) Needs Fixing
Vo Minh Thu Pending
Review via email: mp+79087@code.launchpad.net

Description of the change

Hello,

[FIX]:wrong currency rounding : case(18123)

thanks,
Amit

To post a comment you must log in.
3520. By Raphael Collet (OpenERP)

[MERGE] opw 18120

3521. By Raphael Collet (OpenERP)

[MERGE] opw 17993

Revision history for this message
Lorenzo Battistini (elbati) wrote :

I just realized that the form

round(amount / currency.rounding) * currency.rounding

is also used to allow a generic 'currency.rounding'.

For instance, I could want to allow the following amounts:
0.00 - 0.05 - 0.10 - 0.15 ...
avoiding 0.01 - 0.02 - 0.03 ...
so I would have to set currency.rounding = 0.05

Because of that, maybe we can use something like this:

float(Decimal(str(round(amount / currency.rounding) * currency.rounding)).quantize(Decimal(str(currency.rounding)), rounding=ROUND_HALF_UP))

review: Needs Fixing
3522. By Raphael Collet (OpenERP)

[FIX] revert change 3509, as it introduces a regression

3523. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

3524. By Vo Minh Thu

[MERGE] res_partner.lang field size bumped to 32.
This is needed for instance to accomodate Serbian(Latin).
The size will be used for newly created database as osv.orm does not
handle bumping the size of a selection field on update.

3525. By Vo Minh Thu

[MERGE] fields.many2many: delete instead of update on operation 5 (opw 818189).

3526. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

3527. By Olivier Dony (Odoo)

[FIX] res.currency data: a few missing currencies: XOF,XAF,UGX,HNL,CLP

3528. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

3529. By Amit Dodiya (OpenERP)

[FIX]:wrong currency rounding

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

This is a very dangerous fix (res.currency is a core system object), and inappropriate given the way OpenERP uses floats rather than decimals.

Our floating point calculations are all performed with floats, and we have appropriate solutions for all cases based on floats. So for consistency, please do not introduce the use of Decimal in patches. For more info on the everlasting Float vs. Decimal discussion, see [1].

Here the problem is the equality comparison in account_voucher. For checking that 2 amounts are equal with regard to an appropriate precision, the 2 amounts should be subtracted and checked with res.currency.is_zero().
You can see other examples of how this is done in other places in the code, for example [2].

Thanks!

[1] https://lists.launchpad.net/openerp-expert-accounting/msg00067.html
[2] http://bazaar.launchpad.net/~openerp/openobject-addons/trunk/view/5493/account_voucher/account_voucher.py#L940

review: Disapprove
Revision history for this message
Xavier ALT (dex-phx) wrote :

Hi Amit,

I'm going to reject this one, for those reasons:

- too dangerous for stable branch is the current state of the MP
- introducing "decimal" is not desired here, rounding should stick to float for performance reason
- v6.1/trunk already improved that, perhaps a clean backport should be solution.

Regards,
Xavier

Unmerged revisions

3529. By Amit Dodiya (OpenERP)

[FIX]:wrong currency rounding

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/base/res/res_currency.py'
2--- bin/addons/base/res/res_currency.py 2011-10-12 14:15:50 +0000
3+++ bin/addons/base/res/res_currency.py 2011-11-02 11:30:30 +0000
4@@ -22,6 +22,7 @@
5 import netsvc
6 from osv import fields, osv
7 import ir
8+from decimal import *
9
10 from tools.misc import currency
11 from tools.translate import _
12@@ -94,7 +95,7 @@
13 else:
14 # /!\ First member below must be rounded to full unit!
15 # Do not pass a rounding digits value to round()
16- return round(amount / currency.rounding) * currency.rounding
17+ return float(Decimal(str(round(amount / currency.rounding) * currency.rounding)).quantize(Decimal(str(currency.rounding)), rounding=ROUND_HALF_UP))
18
19 def is_zero(self, cr, uid, currency, amount):
20 return abs(self.round(cr, uid, currency, amount)) < currency.rounding