From a2313b6311c096bdc1f1d006ddd1d23108c86628 Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Tue, 11 Nov 2014 16:18:27 +0100 Subject: [PATCH] [FIX] point_of_sale: correctly handle the rounding when the unit's rounding is set to zero --- addons/point_of_sale/static/src/js/models.js | 9 +++++++-- addons/web/static/src/js/formats.js | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index f2285b8a31e..fadb4ba819c 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -689,8 +689,13 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal var quant = parseFloat(quantity) || 0; var unit = this.get_unit(); if(unit){ - this.quantity = round_pr(quant, unit.rounding); - this.quantityStr = this.quantity.toFixed(Math.ceil(Math.log(1.0 / unit.rounding) / Math.log(10))); + if (unit.rounding) { + this.quantity = round_pr(quant, unit.rounding); + this.quantityStr = this.quantity.toFixed(Math.ceil(Math.log(1.0 / unit.rounding) / Math.log(10))); + } else { + this.quantity = round_pr(quant, 1); + this.quantityStr = this.quantity.toFixed(0); + } }else{ this.quantity = quant; this.quantityStr = '' + this.quantity; diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index 3d7b574e56a..3f2e1351fd2 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -335,13 +335,13 @@ instance.web.auto_date_to_str = function(value, type) { * performs a half up rounding with arbitrary precision, correcting for float loss of precision * See the corresponding float_round() in server/tools/float_utils.py for more info * @param {Number} the value to be rounded - * @param {Number} a non zero precision parameter. eg: 0.01 rounds to two digits. + * @param {Number} a precision parameter. eg: 0.01 rounds to two digits. */ instance.web.round_precision = function(value, precision){ - if(!value){ + if (!value) { return 0; - }else if(!precision){ - throw new Error('round_precision(...): Cannot round value: '+value+' with a precision of zero (or undefined)'); + } else if (!precision || precision < 0) { + precision = 1; } var normalized_value = value / precision; var epsilon_magnitude = Math.log(Math.abs(normalized_value))/Math.log(2);