Skip to content
Snippets Groups Projects
Commit a238c7f5 authored by Hubert Van de Walle (huvw)'s avatar Hubert Van de Walle (huvw)
Browse files

[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#97806

X-original-commit: 9d518f84
Signed-off-by: default avatarJorge Pinna Puissant (jpp) <jpp@odoo.com>
Signed-off-by: default avatarHubert Van De Walle <huvw@odoo.com>
parent c91cf1a2
No related branches found
No related tags found
No related merge requests found
......@@ -628,6 +628,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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment