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/session.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/session.js')
| -rw-r--r-- | addons/web/static/src/js/framework/session.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/addons/web/static/src/js/framework/session.js b/addons/web/static/src/js/framework/session.js index 5f6d4c91ea2..8b084f640fd 100644 --- a/addons/web/static/src/js/framework/session.js +++ b/addons/web/static/src/js/framework/session.js @@ -40,6 +40,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { this.name = "instance0"; // TODO: session store in cookie should be optional this.qweb_mutex = new utils.Mutex(); + this.currencies = {}; }, setup: function(origin, options) { // must be able to customize server @@ -169,7 +170,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { var to_load = _.difference(result, self.module_list).join(','); self.module_list = all_modules; - var loaded = self.load_translations(); + var loaded = $.when(self.load_currencies(), self.load_translations()); var locale = "/web/webclient/locale/" + self.user_context.lang || 'en_US'; var file_list = [ locale ]; if(to_load.length) { @@ -190,6 +191,16 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { }); }); }, + load_currencies: function() { + this.currencies = {}; + var self = this; + return new openerp.web.Model("res.currency").query(["symbol", "position", "decimal_places"]).all() + .then(function(value) { + _.each(value, function(k){ + self.currencies[k.id] = {'symbol': k.symbol, 'position': k.position, 'digits': [69,k.decimal_places]}; + }); + }); + }, load_translations: function() { return _t.database.load_translations(this, this.module_list, this.user_context.lang); }, @@ -240,6 +251,9 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { this.module_loaded[mod] = true; } }, + get_currency: function(currency_id) { + return this.currencies[currency_id]; + }, get_file: function (options) { if (this.override_session){ options.data.session_id = this.session_id; |
