[FIX] product: _compute_qty: first round before ceiling, to avoid pathological cases

Fixes problem when we try to sell 12 units of a product and change it to 1 dozen,
the algorithm was then trying to recompute the original amount and was getting
12,0000048 as a result which was then passed to the ceiling method, getting 13.0!

See also previous commit and issue #1125, PR #1126
This commit is contained in:
Cedric Snauwaert 2014-09-24 16:09:28 +02:00 committed by Olivier Dony
parent d4972ffdb6
commit 311c77bb88
1 changed files with 5 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from openerp.osv import osv, fields
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
from openerp.tools.float_utils import float_round
def ean_checksum(eancode):
"""returns the checksum of an ean string of length 13, returns -1 if the string has the wrong length"""
@ -176,7 +177,10 @@ class product_uom(osv.osv):
raise osv.except_osv(_('Error!'), _('Conversion from Product UoM %s to Default UoM %s is not possible as they both belong to different Category!.') % (from_unit.name,to_unit.name,))
else:
return qty
amount = qty / from_unit.factor
# First round to the precision of the original unit, so that
# float representation errors do not bias the following ceil()
# e.g. with 1 / (1/12) we could get 12.0000048, ceiling to 13!
amount = float_round(qty/from_unit.factor, precision_rounding=from_unit.rounding)
if to_unit:
amount = ceiling(amount * to_unit.factor, to_unit.rounding)
return amount