openerp-india team mailing list archive
-
openerp-india team
-
Mailing list archive
-
Message #00530
[Bug 881356] Re: Floating Point / Rounding issue in stock partial picking wizard
Indeed, floating point values should not be compared with normal
operators (except when they come directly from postgres), the usual way
to do it is to subtract the 2 values and check the result against the
precision limit.
For example, the res.currency object has a is_zero() method that will
check that a given float value is small enough to be considered zero at
the given currency precision, and can be used for all such comparisons.
The same technique should be applied here, subtract the 2 values and
check that they are bigger than the "epsilon" for the current precision.
PS: for those wondering about the Decimal class, keep in mind that we
don't use Decimal for OpenERP, our floating point calculations are all
performed with floats, and we have appropriate solutions for all cases
based on floats. So for consistency, Decimal use should not be
introduced by mistake. For more info on the everlasting Float vs.
Decimal discussion, see [1].
[1] https://lists.launchpad.net/openerp-expert-accounting/msg00067.html
** Changed in: openobject-addons
Importance: Undecided => Medium
** Changed in: openobject-addons
Status: New => Confirmed
** Changed in: openobject-addons
Assignee: OpenERP Publisher's Warranty Team (openerp-opw) => OpenERP R&D Addons Team 2 (openerp-dev-addons2)
** Also affects: openobject-addons/6.0
Importance: Undecided
Status: New
** Changed in: openobject-addons/6.0
Importance: Undecided => Medium
** Changed in: openobject-addons/6.0
Status: New => Confirmed
** Changed in: openobject-addons/6.0
Milestone: None => 6.0.4
** Changed in: openobject-addons/6.0
Assignee: (unassigned) => OpenERP Publisher's Warranty Team (openerp-opw)
** Changed in: openobject-addons
Milestone: None => 6.1
--
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/881356
Title:
Floating Point / Rounding issue in stock partial picking wizard
Status in OpenERP Addons (modules):
Confirmed
Status in OpenERP Addons 6.0 series:
Confirmed
Bug description:
We encountered an Floating Point rounding issue, in the Partial
Picking wizard (stock/wizard/stock_partial_picking.py, do_partial)
"Processing quantity 390.268 kg for $PRODUCT is larger than the
available quantity 390.268 kg."
(Decimal Precision of Product UoM is set to 3, UoM Rounding for kg is
0.001)
OK, so I added an output of the test
if calc_qty > move.move_id.product_qty:
390.268 > 390.268
As one would say, 390.268 > 390.268 should be false...
But:
calc_qty - move.move_id.product_qty => 390.268 - 390.268 is 5.68434188608e-14
This is beyond the default python %s rounding of 6 decimals (to understand the 390.268 > 290.268 output above)
So here is a real problem with rounding precision and float (instead of decimal) data type.
I changed the query to regard decimal precision:
prec = dp.get_precision('Product UoM')(cr)[1] or 0
if int(calc_qty * (10**prec)) > int(move.move_id.product_qty * (10**prec)):
and it works fine.
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/881356/+subscriptions