Skip to content
Snippets Groups Projects
Commit 32d669da authored by Aaron Bohy's avatar Aaron Bohy
Browse files

[FIX] web: correctly parse monetary fields

Before this rev., the function that parses monetary fields (i.e.
the one that converts the string value of the input into a
numerical value) totally ignored the sign of the value.

Actually, parsing a monetary field is exactly the same as parsing
a float field, so we simply use the same function.
parent 794345ba
Branches
Tags
No related merge requests found
......@@ -401,14 +401,6 @@ function parseInteger(value) {
return parsed;
}
function parseMonetary(formatted_value) {
var l10n = core._t.database.parameters;
var value = formatted_value.replace(l10n.thousands_sep, '')
.replace(l10n.decimal_point, '.')
.match(/([0-9]+(\.[0-9]*)?)/)[1];
return parseFloat(value);
}
/**
* Creates an object with id and display_name.
*
......@@ -468,7 +460,7 @@ return {
integer: parseInteger,
many2many: _.identity, // todo
many2one: parseMany2one,
monetary: parseMonetary,
monetary: parseFloat,
one2many: _.identity,
reference: _.identity, // todo
selection: _.identity, // todo
......
......@@ -92,5 +92,27 @@ QUnit.test('format one2many', function(assert) {
assert.strictEqual(fieldUtils.format.one2many({data: [1]}), '1 record');
assert.strictEqual(fieldUtils.format.one2many({data: [1, 2]}), '2 records');
});
QUnit.test('parse float', function(assert) {
assert.expect(6);
assert.strictEqual(fieldUtils.parse.float(""), 0);
assert.strictEqual(fieldUtils.parse.float("0"), 0);
assert.strictEqual(fieldUtils.parse.float("100.00"), 100);
assert.strictEqual(fieldUtils.parse.float("-100.00"), -100);
assert.strictEqual(fieldUtils.parse.float("1,000.00"), 1000);
assert.strictEqual(fieldUtils.parse.float("1,000,000.00"), 1000000);
});
QUnit.test('parse monetary', function(assert) {
assert.expect(6);
assert.strictEqual(fieldUtils.parse.monetary(""), 0);
assert.strictEqual(fieldUtils.parse.monetary("0"), 0);
assert.strictEqual(fieldUtils.parse.monetary("100.00"), 100);
assert.strictEqual(fieldUtils.parse.monetary("-100.00"), -100);
assert.strictEqual(fieldUtils.parse.monetary("1,000.00"), 1000);
assert.strictEqual(fieldUtils.parse.monetary("1,000,000.00"), 1000000);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment