diff options
| author | Cedric Snauwaert <csn@openerp.com> | 2015-01-14 09:47:15 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2015-04-09 19:05:44 +0200 |
| commit | 9d87d15db6dd40a5a0162fb126c725a2f0a40414 (patch) | |
| tree | 304ee05b40ea8fa4d3c0c6ba962534c479320d41 /addons/web/static/src/js/framework/formats.js | |
| parent | 1ebd67355ae981d391fb4c2869027214554df136 (diff) | |
[ADD] new fields.Monetary + updated widgets
Enhance current widget="monetary" client-side feature and
convert it to a first-class type of field, allowing proper
server-side behavior.
- fields: add field.Monetary, similar to fields.Float but
supporting a `currency_field` attribute instead of the
decimal_precision attribute.
`currency_field` indicates the field holding the
related currency on the same record.
The symbol of that currency is used when displaying
the field, and the rounding of the currency is applied
instead of the usual decimal precision.
- avoids application of a second decimal precision rounding,
as was the case when the model field was a `fields.float`.
- removes the need for adding explicit boilerplate to each
view containing a monetary field, i.e.:
widget="monetary" options="{'currency_field': 'currency_id'}"
- res.currency: add new field decimal_places needed to round
value at the correct decimal places
- web: cache all currencies, rounding and symbols at
webclient startup to speedup monetary fields
- new widget monetary for list view + adapt widget monetary
on form view
Limitations:
- if the currency_field is a related field, the server-side
application of currency rounding will only work when the
record already exists, not during creation (to be fixed)
- this field is only supported in the new API
Diffstat (limited to 'addons/web/static/src/js/framework/formats.js')
| -rw-r--r-- | addons/web/static/src/js/framework/formats.js | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/addons/web/static/src/js/framework/formats.js b/addons/web/static/src/js/framework/formats.js index a8dc52bee4a..9efd799a481 100644 --- a/addons/web/static/src/js/framework/formats.js +++ b/addons/web/static/src/js/framework/formats.js @@ -46,6 +46,7 @@ function format_value (value, descriptor, value_if_empty) { case 'integer': return utils.insert_thousand_seps( _.str.sprintf('%d', value)); + case 'monetary': case 'float': var digits = descriptor.digits ? descriptor.digits : [69,2]; digits = typeof digits === "string" ? py.eval(digits) : digits; @@ -133,6 +134,7 @@ function parse_value (value, descriptor, value_if_empty) { if (isNaN(tmp) || tmp % 1) throw new Error(_.str.sprintf(_t("'%s' is not a correct integer"), value)); return tmp; + case 'monetary': case 'float': tmp = Number(value); if (!isNaN(tmp)) |
