diff options
| author | David Monjoie <dmo@odoo.com> | 2017-03-07 16:39:57 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 160dd6a7e601d7b6fa2fd4b27ac08ff851deb364 (patch) | |
| tree | 7b476a045cc6d9294e0498e5b8525abe04adfa6d /addons/web/static/src/js/fields/basic_fields.js | |
| parent | 6e1875ac7e9a6fea9c44d00b3fe7a2c23c9bbb6f (diff) | |
[FIX] web: apply digits option from view on float fields
Previously, only the value in the python description of the field
could be used.
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 30 |
1 files changed, 23 insertions, 7 deletions
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 = $('<span>').addClass('o_form_field o_form_field_number').text(this._formatValue(value)); this.$el.html($span); |
