[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
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user