[FIX] point_of_sale: correctly handle the rounding when the unit's rounding is set to zero

This commit is contained in:
Frederic van der Essen 2014-11-11 16:18:27 +01:00
parent b8efdbdf39
commit a2313b6311
2 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -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);