From bbe944c8298555238708141a90bf45df3cc295ce Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Tue, 24 Dec 2019 10:05:17 +0000 Subject: [PATCH] [FIX] web: avoid parsing value if already number When accessing stock_barcode module to validate pickings, is not possible to add floating point quantities for any localizaton which uses ',' as decimal separator. The numeric field is now defined via browser tags to make the numeric keyboard popup automatically on mobile devices (commit 8f5840369b28962ab2be9edfce7331a836c3df22) Adding the override to avoid further processing when the input is already anumber opw-2154657 closes odoo/odoo#42748 X-original-commit: 1ccc60deeb067f8d461d48cbf51719317c22cb90 Signed-off-by: Nicolas Lempereur (nle) --- .../web/static/src/js/fields/basic_fields.js | 16 +++++++++ .../static/tests/fields/basic_fields_tests.js | 36 +++++++++++++++++++ 2 files changed, 52 insertions(+) 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);