From 8e017ee296d955713f86f1395d00a7d9d9e59985 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 20 Mar 2018 16:54:49 +0100 Subject: [IMP] web: add a percentage formatter This rev. adds a new formatter for numerical values to fieldsUtils. --- addons/web/static/src/js/fields/field_utils.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 5a11f1b0ba8..989f99c5fef 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -29,12 +29,12 @@ var _t = core._t; /** * Convert binary to bin_size - * + * * @param {string} [value] base64 representation of the binary (might be already a bin_size!) * @param {Object} [field] - * a description of the field (note: this parameter is ignored) + * a description of the field (note: this parameter is ignored) * @param {Object} [options] additional options (note: this parameter is ignored) - * + * * @returns {string} bin_size (which is human-readable) */ function formatBinary(value, field, options) { @@ -320,7 +320,19 @@ function formatMonetary(value, field, options) { return currency.symbol + ' ' + formatted_value; } } - +/** + * Returns a string representing the given value (multiplied by 100) + * concatenated with '%'. + * + * @param {number | false} value + * @param {Object} [field] + * @param {Object} [options] + * @returns {string} + */ +function formatPercentage(value, field, options) { + value = formatFloat(value * 100, field, options) || '0'; + return parseFloat(value) + "%"; +} /** * Returns a string representing the value of the selection. * @@ -591,6 +603,7 @@ return { many2one: formatMany2one, monetary: formatMonetary, one2many: formatX2Many, + percentage: formatPercentage, reference: formatMany2one, selection: formatSelection, text: formatChar, -- cgit v1.2.3