[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 https://github.com/odoo/odoo/pull/97425 , `parseMonetary` wrongly assumed that a currency was always passed in the parameters opw-2937403 closes odoo/odoo#97861 X-original-commit: 9d518f847d2204fc5159a92bc4e4de655acf88fa Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com> Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
@@ -629,6 +629,9 @@ function parseMonetary(value, field, options) {
|
||||
}
|
||||
currency = session.get_currency(currency_id);
|
||||
}
|
||||
if (!currency) {
|
||||
return parseFloat(value);
|
||||
}
|
||||
if (!value.includes(currency.symbol)) {
|
||||
throw new Error(_.str.sprintf(core._t("'%s' is not a correct monetary field"), value));
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ QUnit.test('parse integer', function(assert) {
|
||||
});
|
||||
|
||||
QUnit.test('parse monetary', function(assert) {
|
||||
assert.expect(13);
|
||||
assert.expect(15);
|
||||
var originalCurrencies = session.currencies;
|
||||
const originalParameters = _.clone(core._t.database.parameters);
|
||||
session.currencies = {
|
||||
@@ -293,11 +293,13 @@ QUnit.test('parse monetary', function(assert) {
|
||||
const nbsp = '\u00a0';
|
||||
_.extend(core._t.database.parameters, {
|
||||
grouping: [3, 0],
|
||||
decimal_point: ',',
|
||||
decimal_point: '.',
|
||||
thousands_sep: nbsp,
|
||||
});
|
||||
assert.strictEqual(fieldUtils.parse.monetary(`1${nbsp}000.00${nbsp}€`, {}, {currency_id: 1}), 1000);
|
||||
assert.strictEqual(fieldUtils.parse.monetary(`$${nbsp}1${nbsp}000.00`, {}, {currency_id: 3}), 1000);
|
||||
assert.strictEqual(fieldUtils.parse.monetary(`1${nbsp}000.00`), 1000);
|
||||
assert.strictEqual(fieldUtils.parse.monetary(`1${nbsp}000${nbsp}000.00`), 1000000);
|
||||
|
||||
session.currencies = originalCurrencies;
|
||||
core._t.database.parameters = originalParameters;
|
||||
|
||||
Reference in New Issue
Block a user