diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-11-12 13:06:48 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-11-12 13:06:48 +0100 |
| commit | 99d0e1b80e5b2d5eb59b96c6ce1bf246f8df2326 (patch) | |
| tree | 6c53282f8a22e9b59d83762ebe057173172c5f63 /addons/web/static/src/js/fields | |
| parent | 4d53266e236d1816e45b13aa50bcafb1bab2bc8c (diff) | |
| parent | a403155dec769418ede3c9128a887847f97a956f (diff) | |
[MERGE] forward port branch 12.0 up to a403155dec7
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 9d40c88019d..bbdee83c4f9 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -587,6 +587,22 @@ function parseFloatTime(value) { } /** + * Parse a String containing a percentage and convert it to float. + * The percentage can be a regular xx.xx float or a xx%. + * + * @param {string} value + * The string to be parsed + * @returns {float} + * @throws {Error} if the value couldn't be converted to float + */ +function parsePercentage(value) { + if (value.slice(-1) === '%') { + return parseFloat(value.slice(0, -1)) / 100; + } + return parseFloat(value); +} + +/** * Parse a String containing integer with language formating * * @param {string} value @@ -668,6 +684,7 @@ return { many2one: parseMany2one, monetary: parseMonetary, one2many: _.identity, + percentage: parsePercentage, reference: parseMany2one, selection: _.identity, // todo text: _.identity, // todo |
