summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2018-09-27 09:44:28 +0200
committerMathieu Duckerts-Antoine <dam@odoo.com>2018-09-27 11:58:39 +0200
commit3c093a8108409f74f0c7ca9770be04896fc149f7 (patch)
tree77c4da9f24fe0705487b89ad25700f0e3264e939 /addons/web/static/src
parent49695b0088ed6ac239faca2653470032ad10fdb5 (diff)
[FIX] web: human numbers and percentages
A recent modification of the float and integer formatters allowing the rendering to be human readable causes a bug in the percentage formatter for large values. The reason is that the latter formatter uses formatFloat (wich can now produce 'numbers' like 3k) and then parse the result. In the case of 3k an error is raised since 3k is not recognized as a true number. This fixes avoid to parse the number in case it has been formatted to be 'readable'. Note that the parsing was essentially used to produces better percentages like 10% instead of 10.00%. This is not necessary in our case since utils.human_number takes care of the unwanted (not all) decimals for us (the original number is always rounded by utils.human_number).
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/fields/field_utils.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index 750cf055cdf..9d40c88019d 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -354,11 +354,16 @@ function formatMonetary(value, field, options) {
* @param {number | false} value
* @param {Object} [field]
* @param {Object} [options]
+ * @param {function} [options.humanReadable] if returns true, parsing is avoided
* @returns {string}
*/
function formatPercentage(value, field, options) {
- value = formatFloat(value * 100, field, options) || '0';
- return parseFloat(value) + "%";
+ options = options || {};
+ var result = formatFloat(value * 100, field, options) || '0';
+ if (options.humanReadable && options.humanReadable(value * 100)) {
+ return result + "%";
+ }
+ return parseFloat(result) + "%";
}
/**
* Returns a string representing the value of the selection.