[FIX] product: when converting unit of mesures, round above instead of mathematical rounding

bzr revid: mat@openerp.com-20140305171456-goo7on3ncfihu0wu
This commit is contained in:
Martin Trigaux 2014-03-05 18:14:56 +01:00
parent e231045095
commit 1967b6ce19
3 changed files with 18 additions and 10 deletions

View File

@ -18,12 +18,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import tools
import math
import logging
_logger = logging.getLogger(__name__)
def rounding(f, r):
# TODO for trunk: log deprecation warning
# _logger.warning("Deprecated rounding method, please use tools.float_round to round floats.")
return tools.float_round(f, precision_rounding=r)
# TODO for trunk: add rounding method parameter to tools.float_round and remove this method
def ceiling(f, r):
if not r:
return f
return round(f / r) * r
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
return math.ceil(f / r) * r

View File

@ -21,7 +21,7 @@
import time
from _common import rounding
from _common import ceiling
from openerp.osv import fields, osv
from openerp.tools.translate import _
@ -296,7 +296,7 @@ class product_pricelist(osv.osv):
if price is not False:
price_limit = price
price = price * (1.0+(res['price_discount'] or 0.0))
price = rounding(price, res['price_round']) #TOFIX: rounding with tools.float_rouding
price = ceiling(price, res['price_round'])
price += (res['price_surcharge'] or 0.0)
if res['price_min_margin']:
price = max(price, price_limit+res['price_min_margin'])

View File

@ -22,7 +22,7 @@
import math
import re
from _common import rounding
from _common import ceiling
from openerp import tools
from openerp.osv import osv, fields
@ -178,7 +178,7 @@ class product_uom(osv.osv):
return qty
amount = qty / from_unit.factor
if to_unit:
amount = rounding(amount * to_unit.factor, to_unit.rounding)
amount = ceiling(amount * to_unit.factor, to_unit.rounding)
return amount
def _compute_price(self, cr, uid, from_uom_id, price, to_uom_id=False):