diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2019-01-08 13:15:16 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-01-09 08:07:56 +0000 |
| commit | 69f6b9510db36570698e472f797ef5e4e3685d2e (patch) | |
| tree | 7dd711032fd274d97e5e4edcd72db14529059ca3 /addons/web/static | |
| parent | e95b4e959433db45bc5c227f67763cd509fee333 (diff) | |
[FIX] web: decimal separator of percentage
When a percentage if formatted, the decimal separator used is always
`.`, while it should be the decimal separator of the language.
opw-1908220
closes odoo/odoo#30030
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 2 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/field_utils_tests.js | 30 |
2 files changed, 29 insertions, 3 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index bbdee83c4f9..ec99f4fa0f6 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -363,7 +363,7 @@ function formatPercentage(value, field, options) { if (options.humanReadable && options.humanReadable(value * 100)) { return result + "%"; } - return parseFloat(result) + "%"; + return (parseFloat(result) + "%").replace('.', _t.database.parameters.decimal_point); } /** * Returns a string representing the value of the selection. diff --git a/addons/web/static/tests/fields/field_utils_tests.js b/addons/web/static/tests/fields/field_utils_tests.js index 6b7cda13264..940f5674780 100644 --- a/addons/web/static/tests/fields/field_utils_tests.js +++ b/addons/web/static/tests/fields/field_utils_tests.js @@ -135,7 +135,9 @@ QUnit.test('format binary', function (assert) { }); QUnit.test('format percentage', function (assert) { - assert.expect(9); + assert.expect(11); + + var originalParameters = _.clone(core._t.database.parameters); assert.strictEqual(fieldUtils.format.percentage(0), '0%'); assert.strictEqual(fieldUtils.format.percentage(0.5), '50%'); @@ -151,6 +153,16 @@ QUnit.test('format percentage', function (assert) { assert.strictEqual(fieldUtils.format.percentage(50, null, {humanReadable: function (val) {return true;}}), '5k%' ); + + _.extend(core._t.database.parameters, { + grouping: [3, 0], + decimal_point: ',', + thousands_sep: '.' + }); + assert.strictEqual(fieldUtils.format.percentage(0.125), '12,5%'); + assert.strictEqual(fieldUtils.format.percentage(0.666666), '66,67%'); + + core._t.database.parameters = originalParameters; }); QUnit.test('parse float', function(assert) { @@ -262,7 +274,9 @@ QUnit.test('parse monetary', function(assert) { }); QUnit.test('parse percentage', function(assert) { - assert.expect(7); + assert.expect(9); + + var originalParameters = _.clone(core._t.database.parameters); assert.strictEqual(fieldUtils.parse.percentage(""), 0); assert.strictEqual(fieldUtils.parse.percentage("0"), 0); @@ -271,6 +285,18 @@ QUnit.test('parse percentage', function(assert) { assert.strictEqual(fieldUtils.parse.percentage("1"), 1); assert.strictEqual(fieldUtils.parse.percentage("2%"), 0.02); assert.strictEqual(fieldUtils.parse.percentage("100%"), 1); + + _.extend(core._t.database.parameters, { + grouping: [3, 0], + decimal_point: ',', + thousands_sep: '.' + }); + + assert.strictEqual(fieldUtils.parse.percentage("0,04"), 0.04); + assert.strictEqual(fieldUtils.parse.percentage("6,02%"), 0.0602); + + core._t.database.parameters = originalParameters; + }) }); |
