diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2017-12-29 12:18:58 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim-odoo@users.noreply.github.com> | 2018-01-04 11:32:04 +0100 |
| commit | 38e73da092f3bb3377edac983aea37aceed4ed3f (patch) | |
| tree | 25b35e1072dca75e369ca7ffcb27d1864282067d /addons/web/static/src | |
| parent | 8e181c99c233f1a0e068f9218449add174a9a2b6 (diff) | |
[IMP] web: support variable digits
In v10, a `Float` field with `widget="monetary"` option uses the decimal
precision of the field. In v11, however, it uses the decimal precision
of the currency. However, in many cases `widget="monetary"` is used in
the sole purpose of displaying the currency symbol. The precision of the
field sould be kept.
This commit introduces the support of the decimal precision of the field
for this specific use case thanks to the `field_digits` option:
```
<field name="pouet" widget="monetary" options="{'field_digits': True}" />
```
If such an option is used, the field precision will prevail over the
currency precision.
Related to #21686
opw-800279
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 1 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 6 |
2 files changed, 6 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index e823278463a..09406b43711 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -568,6 +568,7 @@ var FieldMonetary = InputField.extend({ this.formatOptions.currency = this.currency; this.formatOptions.digits = [16, 2]; + this.formatOptions.field_digits = this.nodeOptions.field_digits; }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 932ea997e6a..6a6ad5a7a98 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -286,8 +286,12 @@ function formatMonetary(value, field, options) { currency = session.get_currency(currency_id); } + var digits = (currency && currency.digits) || options.digits; + if (options.field_digits === true) { + digits = field.digits || digits; + } var formatted_value = formatFloat(value, field, { - digits: (currency && currency.digits) || options.digits, + digits: digits, }); if (!currency || options.noSymbol) { |
