From 4fb2e76b431d9f587d9f9a67925f6e0e56bdc683 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 10 Mar 2016 14:03:14 +0100 Subject: [FIX] web: `char_domain` rendering on record switch When using the left/riht arrow to switch of record in a form view, the rendering of the `char_domain` widget was done too early, before all fields are ready / set, and if the domain of the previous record could not be applied on the current record, it leaded to a traceback. This revision introduce a new deffered, because I coudln't find one that was doing what I was looking for: - `is_initialized` is a defferred which is resolved when the form view has finished its rendering for the first time - `reload_mutex` is a mutex used only when reloading or switch to left/right record. While the one needed in this case is a deferred which is resolved when the record has finished being rendered, wether when its when coming from the list view to the form view (and it's not the first time the form view is loaded, e.g. list view -> form view -> list view -> form view, another record), or on the switch of left/right record. opw-671594 --- addons/web/static/src/js/view_form.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 92121e75a85..5c7a85f3bc3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -118,6 +118,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM "footer_to_buttons": false, }); this.is_initialized = $.Deferred(); + this.record_loaded = $.Deferred(); this.mutating_mutex = new $.Mutex(); this.save_list = []; this.render_value_defs = []; @@ -329,6 +330,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM this._actualize_mode(); this.set({ 'title' : record.id ? record.display_name : _t("New") }); + this.record_loaded = $.Deferred(); _(this.fields).each(function (field, f) { field._dirty_flag = false; field._inhibit_on_change_flag = true; @@ -344,6 +346,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM self.on_form_changed(); self.rendering_engine.init_fields(); self.is_initialized.resolve(); + self.record_loaded.resolve(); self.do_update_pager(record.id === null || record.id === undefined); if (self.sidebar) { self.sidebar.do_attachement_update(self.dataset, self.datarecord.id); @@ -2568,7 +2571,7 @@ instance.web.form.FieldCharDomain = instance.web.form.AbstractField.extend(insta }); if (this.options.model_field){ this.field_manager.fields[this.options.model_field].on("change:value", this, function(){ - if (self.view && self.view.onchanges_mutex){ + if (self.view && self.view.record_loaded.state == "resolved" && self.view.onchanges_mutex){ self.view.onchanges_mutex.def.then(function(){ self.display_field(); }); -- cgit v1.2.3 From 1aeb747c6e06f11a005331713e5858438cdf8a60 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 16 Mar 2016 11:54:21 +0100 Subject: [FIX] web: len & non zero implementation for wrapping list/dict The implementation of `__len__` & `__nonzero__` were not defined for the py types `wrapping_dict` and `wrapping_list`. For instance, this prevented an empty list to be considered as `False` in domains evaluated by the web client. e.g., in the automatic partner merge wizard, the domain ``` [('id', 'in', partner_ids and partner_ids[0] and partner_ids[0][2] or False)] ``` is used. When the `partner_ids` list was empty (meaning the "partners to merge" list was empty in the wizard), it wasn't considered as `False`, and it therefore attempted to get `partner_ids[0]`, which resulted to a crash, as the list was empty. opw-672095 Closes #11343 Courtesy of Xavier Morel (xmo@odoo.com) --- addons/web/static/src/js/framework/pyeval.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/framework/pyeval.js b/addons/web/static/src/js/framework/pyeval.js index ce25e7af534..2b553d37e0f 100644 --- a/addons/web/static/src/js/framework/pyeval.js +++ b/addons/web/static/src/js/framework/pyeval.js @@ -757,6 +757,12 @@ var wrapping_dict = py.type('wrapping_dict', null, { __getattr__: function (key) { return this.__getitem__(py.str.fromJSON(key)); }, + __len__: function () { + return Object.keys(this._store).length + }, + __nonzero__: function () { + return py.PY_size(this) > 0 ? py.True : py.False; + }, get: function () { var args = py.PY_parseArgs(arguments, ['k', ['d', py.None]]); @@ -780,6 +786,12 @@ var wrapping_list = py.type('wrapping_list', null, { __getitem__: function (index) { return wrap(this._store[index.toJSON()]); }, + __len__: function () { + return this._store.length; + }, + __nonzero__: function () { + return py.PY_size(this) > 0 ? py.True : py.False; + }, fromJSON: function (ar) { var instance = py.PY_call(wrapping_list); instance._store = ar; -- cgit v1.2.3