diff --git a/addons/product/product.py b/addons/product/product.py index 83ab8183f7a..da0ce6f9040 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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