From b6a0874f4cc406788f0bf7045e279f43f8bd82ed Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 25 Oct 2011 10:51:12 +0200 Subject: [PATCH] [FIX] disgusting hack to skip around race condition When clicking on an action button, form view first saves then executes the action. In doing so, it causes the o2m field to call ListView#reload_content twice without waiting for the reloading to end, generating a race condition in ListView.List#render_dataset. As a result, the read_slice callback fills the list twice (once for each #reload_content call), resulting in everything being duplicated. Clear the content of the records collection before adding stuff. note: collections should dedup on ids. lp bug: https://launchpad.net/bugs/877965 fixed bzr revid: xmo@openerp.com-20111025085112-q38q8m0k2mopwadg --- addons/web/static/src/js/view_list.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 4408cab8e3b..bf6f79b9cc0 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -1206,6 +1206,10 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L var options = { offset: page * limit, limit: limit }; //TODO xmo: investigate why we need to put the setTimeout setTimeout(function() {dataset.read_slice(fields, options , function (records) { + // FIXME: ignominious hacks, parents (aka form view) should not send two ListView#reload_content concurrently + if (self.records.length) { + self.records.reset(null, {silent: true}); + } if (!self.datagroup.openable) { view.configure_pager(dataset); } else { @@ -1546,7 +1550,8 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{ * @param {Array} [records] * @returns this */ - reset: function (records) { + reset: function (records, options) { + options = options || {}; _(this._proxies).each(function (proxy) { proxy.reset(); }); @@ -1557,7 +1562,9 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{ if (records) { this.add(records); } - this.trigger('reset', this); + if (!options.silent) { + this.trigger('reset', this); + } return this; }, /**