diff options
| author | Cedric Snauwaert <csn@openerp.com> | 2017-06-29 10:17:42 +0200 |
|---|---|---|
| committer | Cedric Snauwaert <csn@openerp.com> | 2017-06-29 16:37:30 +0200 |
| commit | 07fdcad3439716f4fbe91cadf31ccfca3a49b05f (patch) | |
| tree | 7e79d645331f22cbbe0af4ab93d1674a354ded01 /addons/web/static/tests/fields/field_utils_tests.js | |
| parent | 8473bde80e6609d552af8b00396c72a20bd3c47f (diff) | |
[ADD] web: add parse monetary method
In field_utils, the parse monetary method was remapped to parsefloat. In this commit, we add a specific parseMonetary method to handle currency specific formatting.
Diffstat (limited to 'addons/web/static/tests/fields/field_utils_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/field_utils_tests.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/addons/web/static/tests/fields/field_utils_tests.js b/addons/web/static/tests/fields/field_utils_tests.js index e00d45ef91f..a49197f6e65 100644 --- a/addons/web/static/tests/fields/field_utils_tests.js +++ b/addons/web/static/tests/fields/field_utils_tests.js @@ -2,6 +2,7 @@ odoo.define('web.field_utils_tests', function (require) { "use strict"; var core = require('web.core'); +var session = require('web.session'); var fieldUtils = require('web.field_utils'); QUnit.module('fields', {}, function () { @@ -122,7 +123,20 @@ QUnit.test('parse float', function(assert) { }); QUnit.test('parse monetary', function(assert) { - assert.expect(6); + assert.expect(11); + var originalCurrencies = session.currencies; + session.currencies = { + 1: { + digits: [69, 2], + position: "after", + symbol: "€" + }, + 3: { + digits: [69, 2], + position: "before", + symbol: "$" + } + }; assert.strictEqual(fieldUtils.parse.monetary(""), 0); assert.strictEqual(fieldUtils.parse.monetary("0"), 0); @@ -130,6 +144,13 @@ QUnit.test('parse monetary', function(assert) { 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); + assert.strictEqual(fieldUtils.parse.monetary("$ 125.00", {}, {currency_id: 3}), 125); + assert.strictEqual(fieldUtils.parse.monetary("1,000.00 €", {}, {currency_id: 1}), 1000); + assert.throws(function() {fieldUtils.parse.monetary("$ 12.00", {}, {currency_id: 3})}, /is not a correct/); + assert.throws(function() {fieldUtils.parse.monetary("$ 12.00", {}, {currency_id: 1})}, /is not a correct/); + assert.throws(function() {fieldUtils.parse.monetary("$ 12.00 34", {}, {currency_id: 3})}, /is not a correct/); + + session.currencies = originalCurrencies; }); }); }); |
