[FIX] web_widget_numeric_step: Float Precision

pull/2109/head
Alexandre Díaz 2020-02-25 21:55:04 +01:00 committed by Thanakrit Pintana
parent 6c6566078a
commit 8357085d1d
2 changed files with 11 additions and 14 deletions

View File

@ -5,7 +5,7 @@
{ {
'name': "Web Widget Numeric Step", 'name': "Web Widget Numeric Step",
'category': "web", 'category': "web",
'version': "12.0.1.0.0", 'version': "12.0.1.1.0",
'author': "GRAP, Tecnativa, " 'author': "GRAP, Tecnativa, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@ -5,6 +5,7 @@
odoo.define('web_widget_numeric_step.field', function (require) { odoo.define('web_widget_numeric_step.field', function (require) {
"use strict"; "use strict";
var field_utils = require('web.field_utils');
var Registry = require('web.field_registry'); var Registry = require('web.field_registry');
var FieldFloat = require('web.basic_fields').FieldFloat; var FieldFloat = require('web.basic_fields').FieldFloat;
@ -204,18 +205,6 @@ odoo.define('web_widget_numeric_step.field', function (require) {
}, },
// Helper Functions // Helper Functions
/*
* Get field precision (really used by floats)
*/
_getPrecision: function () {
var field = this.record.fields[this.name];
if (field && 'digits' in field && field.digits.length === 2) {
return field.digits[1];
}
return 0;
},
/** /**
* Check limits and precision of the value. * Check limits and precision of the value.
* If the value 'is not a number', the function does nothing to * If the value 'is not a number', the function does nothing to
@ -234,7 +223,15 @@ odoo.define('web_widget_numeric_step.field', function (require) {
} else if (!_.isNaN(this._config.max) && cval > this._config.max) { } else if (!_.isNaN(this._config.max) && cval > this._config.max) {
cval = this._config.max; cval = this._config.max;
} }
return cval.toFixed(this._getPrecision());
var field = this.record.fields[this.name];
var formattedValue = field_utils.format[field.type](cval, field, {
data: this.record.data,
escape: true,
isPassword: false,
digits: field.digits,
});
return formattedValue;
}, },
}); });