From 160dd6a7e601d7b6fa2fd4b27ac08ff851deb364 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 7 Mar 2017 16:39:57 +0100 Subject: [FIX] web: apply digits option from view on float fields Previously, only the value in the python description of the field could be used. --- addons/web/static/src/js/fields/basic_fields.js | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 779420b6d3d..12699658a7b 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -277,16 +277,32 @@ var FieldInteger = InputField.extend({ var FieldFloat = InputField.extend({ supportedFieldTypes: ['float'], - _renderReadonly: function () { - var precision; - var value = this.value; + + /** + * Float fields have an additional precision parameter that is read from + * either the field node in the view or the field python definition itself. + * + * @override + */ + init: function () { + this._super.apply(this, arguments); if (this.attrs.digits) { - precision = this.node.attrs.digits; + this.nodeOptions.digits = JSON.parse(this.attrs.digits); } else { - precision = this.field.digits; + this.nodeOptions.digits = this.field.digits; } - if (precision && precision.length === 2) { - value = utils.round_decimals(value, precision[1]); + }, + + /** + * Format value according to precision parameter. + * + * @override + * @private + */ + _renderReadonly: function () { + var value = this.value; + if (this.nodeOptions.digits && this.nodeOptions.digits.length === 2) { + value = utils.round_decimals(value, this.nodeOptions.digits[1]); } var $span = $('').addClass('o_form_field o_form_field_number').text(this._formatValue(value)); this.$el.html($span); -- cgit v1.2.3