[FIX] web: parse numebr (separator not set)
Steps to reproduce: - select a language where thousands separator is not (e.g. portugese) - try editing any number input field Bug: error when parsing the new value when thousands separator is not defined Fix: fixed default value (only fallback to commas if it's not the decimal Point separator) opw-3041135 closes odoo/odoo#105312 X-original-commit: 71712acdf259aca7745a8a0b41a022d3abdcb047 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -33,8 +33,8 @@ function evaluateMathematicalExpression(expr, context = {}) {
|
||||
*
|
||||
* @param {string} value
|
||||
* @param {Object} options - additional options
|
||||
* @param {string|RegExp} [options.thousandsSep] - the thousands separator used in the value
|
||||
* @param {string|RegExp} [options.decimalPoint] - the decimal point used in the value
|
||||
* @param {string|RegExp} options.thousandsSep - the thousands separator used in the value
|
||||
* @param {string|RegExp} options.decimalPoint - the decimal point used in the value
|
||||
* @returns {number}
|
||||
*/
|
||||
function parseNumber(value, options = {}) {
|
||||
@@ -66,7 +66,7 @@ export class InvalidNumberError extends Error {}
|
||||
* @returns {number} a float
|
||||
*/
|
||||
export function parseFloat(value) {
|
||||
const thousandsSepRegex = localization.thousandsSep;
|
||||
const thousandsSepRegex = localization.thousandsSep || "";
|
||||
const decimalPointRegex = localization.decimalPoint;
|
||||
let parsed = parseNumber(value, {
|
||||
thousandsSep: thousandsSepRegex,
|
||||
@@ -116,7 +116,7 @@ export function parseFloatTime(value) {
|
||||
* @returns {number} an integer
|
||||
*/
|
||||
export function parseInteger(value) {
|
||||
const thousandsSepRegex = localization.thousandsSep;
|
||||
const thousandsSepRegex = localization.thousandsSep || "";
|
||||
const decimalPointRegex = localization.decimalPoint;
|
||||
let parsed = parseNumber(value, {
|
||||
thousandsSep: thousandsSepRegex,
|
||||
|
||||
@@ -39,6 +39,9 @@ QUnit.module("Fields", (hooks) => {
|
||||
|
||||
patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: "." });
|
||||
assert.strictEqual(parseFloat("1.234,567"), 1234.567);
|
||||
|
||||
patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: false });
|
||||
assert.strictEqual(parseFloat("1234,567"), 1234.567);
|
||||
});
|
||||
|
||||
QUnit.test("parseFloatTime", function (assert) {
|
||||
@@ -73,6 +76,9 @@ QUnit.module("Fields", (hooks) => {
|
||||
expectInvalidNumberError(assert, parseInteger, "1.234,567");
|
||||
// fallback to en localization
|
||||
assert.strictEqual(parseInteger("1,000,000"), 1000000);
|
||||
|
||||
patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: false });
|
||||
assert.strictEqual(parseInteger("1000000"), 1000000);
|
||||
});
|
||||
|
||||
QUnit.test("parsePercentage", function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user