diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 37e61c8fd5b..6b2e9cbe7c7 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -430,6 +430,22 @@ var NumericField = InputField.extend({ return this._super.apply(this, arguments); }, + /** + * Parse numerical value (integer or float) + * + * Note: We have to overwrite this method to skip the format if we are into + * edit mode on a input type number. + * + * @override + * @private + */ + _parseValue: function (value) { + if (this.mode === 'edit' && this.nodeOptions.type === 'number') { + return Number(value); + } + return this._super.apply(this, arguments); + }, + /** * Formats an input element for edit mode. This is in a separate function so * extending widgets can use it on their input without having input as tagName. diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 99cf151baf9..2e24dd38740 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -837,6 +837,42 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('float field with type number option and comma decimal separator', async function (assert) { + assert.expect(4); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '', + res_id: 4, + translateParameters: { + thousands_sep: ".", + decimal_point: ",", + grouping: [3, 0], + }, + }); + + await testUtils.form.clickEdit(form); + assert.ok(form.$('.o_field_widget')[0].hasAttribute('type'), + 'Float field with option type must have a type attribute.'); + assert.hasAttrValue(form.$('.o_field_widget'), 'type', 'number', + 'Float field with option type must have a type attribute equals to "number".'); + await testUtils.fields.editInput(form.$('input[name=qux]'), '123456.789'); + await testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + assert.strictEqual(form.$('.o_field_widget').val(), '123456.789', + 'Float value must be not formatted if input type is number.'); + await testUtils.form.clickSave(form); + assert.strictEqual(form.$('.o_field_widget').text(), '123.456,8', + 'Float value must be formatted in readonly view even if the input type is number.'); + + form.destroy(); + }); + + QUnit.test('float field without type number option', async function (assert) { assert.expect(2);