Skip to content

Commit a238c7f

Browse files
committed
[FIX] web: parseMonetary with NBSP as a thousands separator and no currency
Steps to reproduce: - Switch language to french - Refresh the page - Create a new payment - Select a partner - Enter an amount of 100000,00 - Save the record -> The following field is incorrect: amount Cause of the issue: Since odoo#97425 , `parseMonetary` wrongly assumed that a currency was always passed in the parameters opw-2937403 closes odoo#97806 X-original-commit: 9d518f8 Signed-off-by: Jorge Pinna Puissant (jpp) <[email protected]> Signed-off-by: Hubert Van De Walle <[email protected]>
1 parent c91cf1a commit a238c7f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

addons/web/static/src/js/fields/field_utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ function parseMonetary(value, field, options) {
628628
}
629629
currency = session.get_currency(currency_id);
630630
}
631+
if (!currency) {
632+
return parseFloat(value);
633+
}
631634
if (!value.includes(currency.symbol)) {
632635
throw new Error(_.str.sprintf(core._t("'%s' is not a correct monetary field"), value));
633636
}

addons/web/static/tests/fields/field_utils_tests.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ QUnit.test('parse integer', function(assert) {
261261
});
262262

263263
QUnit.test('parse monetary', function(assert) {
264-
assert.expect(13);
264+
assert.expect(15);
265265
var originalCurrencies = session.currencies;
266266
const originalParameters = _.clone(core._t.database.parameters);
267267
session.currencies = {
@@ -293,11 +293,13 @@ QUnit.test('parse monetary', function(assert) {
293293
const nbsp = '\u00a0';
294294
_.extend(core._t.database.parameters, {
295295
grouping: [3, 0],
296-
decimal_point: ',',
296+
decimal_point: '.',
297297
thousands_sep: nbsp,
298298
});
299299
assert.strictEqual(fieldUtils.parse.monetary(`1${nbsp}000.00${nbsp}€`, {}, {currency_id: 1}), 1000);
300300
assert.strictEqual(fieldUtils.parse.monetary(`$${nbsp}1${nbsp}000.00`, {}, {currency_id: 3}), 1000);
301+
assert.strictEqual(fieldUtils.parse.monetary(`1${nbsp}000.00`), 1000);
302+
assert.strictEqual(fieldUtils.parse.monetary(`1${nbsp}000${nbsp}000.00`), 1000000);
301303

302304
session.currencies = originalCurrencies;
303305
core._t.database.parameters = originalParameters;

0 commit comments

Comments
 (0)