diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index e823278463a..09406b43711 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -568,6 +568,7 @@ var FieldMonetary = InputField.extend({ this.formatOptions.currency = this.currency; this.formatOptions.digits = [16, 2]; + this.formatOptions.field_digits = this.nodeOptions.field_digits; }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 932ea997e6a..6a6ad5a7a98 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -286,8 +286,12 @@ function formatMonetary(value, field, options) { currency = session.get_currency(currency_id); } + var digits = (currency && currency.digits) || options.digits; + if (options.field_digits === true) { + digits = field.digits || digits; + } var formatted_value = formatFloat(value, field, { - digits: (currency && currency.digits) || options.digits, + digits: digits, }); if (!currency || options.noSymbol) { diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 6fc104246d6..9ea423250e4 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -587,6 +587,52 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('float field with monetary widget and decimal precision', function (assert) { + assert.expect(5); + + this.data.partner.records = [{ + id: 1, + qux: -8.89859, + currency_id: 1, + }] + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + res_id: 1, + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0-8.9', + 'The value should be displayed properly.'); + + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('input').val(), '-8.9', + 'The input should be rendered without the currency symbol.'); + assert.strictEqual(form.$('input').parent().children().first().text(), '$', + 'The input should be preceded by a span containing the currency symbol.'); + + form.$('input').val('109.2458938598598').trigger('input'); + assert.strictEqual(form.$('input').val(), '109.2458938598598', + 'The value should not be formated yet.'); + + form.$buttons.find('.o_form_button_save').click(); + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0109.2', + 'The new value should be rounded properly.'); + + form.destroy(); + }); + QUnit.module('FieldEmail'); QUnit.test('email field in form view', function (assert) {