diff --git a/addons/web/static/src/views/fields/parsers.js b/addons/web/static/src/views/fields/parsers.js index 6a5eadbbf38..ec986f66535 100644 --- a/addons/web/static/src/views/fields/parsers.js +++ b/addons/web/static/src/views/fields/parsers.js @@ -38,16 +38,16 @@ function evaluateMathematicalExpression(expr, context = {}) { * @returns {number} */ function parseNumber(value, options = {}) { - // a number can have the thousand separator multiple times. ex: 1,000,000.00 - value = value.replaceAll(new RegExp(escapeRegExp(options.thousandsSep), "g") || ",", ""); - // a number only have one decimal separator - value = value.replace(new RegExp(escapeRegExp(options.decimalPoint), "g") || ".", "."); - if (value.startsWith("=")) { value = evaluateMathematicalExpression(value.substring(1)); if (options.truncate) { value = Math.trunc(value); } + } else { + // a number can have the thousand separator multiple times. ex: 1,000,000.00 + value = value.replaceAll(new RegExp(escapeRegExp(options.thousandsSep), "g") || ",", ""); + // a number only have one decimal separator + value = value.replace(new RegExp(escapeRegExp(options.decimalPoint), "g") || ".", "."); } return Number(value); diff --git a/addons/web/static/tests/views/fields/parsers_tests.js b/addons/web/static/tests/views/fields/parsers_tests.js index 95710685404..ba1c2487c52 100644 --- a/addons/web/static/tests/views/fields/parsers_tests.js +++ b/addons/web/static/tests/views/fields/parsers_tests.js @@ -40,6 +40,12 @@ QUnit.module("Fields", (hooks) => { patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: "." }); assert.strictEqual(parseFloat("1.234,567"), 1234.567); + // Can evaluate expression from locale with decimal point different from ".". + assert.strictEqual(parseFloat("=1.000,1 + 2.000,2"), 3000.3); + assert.strictEqual(parseFloat("=1.000,00 + 11.121,00"), 12121); + assert.strictEqual(parseFloat("=1000,00 + 11122,00"), 12122); + assert.strictEqual(parseFloat("=1000 + 11123"), 12123); + patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: false }); assert.strictEqual(parseFloat("1234,567"), 1234.567); });