From b5b8e66b900e78dc3228946e15d517f91a214703 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 14 Aug 2017 12:38:14 +0200 Subject: [FIX] web: grouped views: update pager The problem occured when opening a record from a grouped list or kanban view. In the opened form view, the pager was sometimes incorrect. This was because the list of ids wasn't correctly updated when groups were opened/folded. --- .../web/static/src/js/views/basic/basic_model.js | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 72a89a23cc2..e8409487abc 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -919,18 +919,23 @@ var BasicModel = AbstractModel.extend({ * @returns {Deferred -> string} resolves to the group id */ toggleGroup: function (groupId) { + var self = this; var group = this.localData[groupId]; if (group.isOpen) { group.isOpen = false; group.data = []; + group.res_ids = []; group.offset = 0; + this._updateParentResIDs(group); return $.when(groupId); } if (!group.isOpen) { group.isOpen = true; var def; if (group.count > 0) { - def = this._load(group); + def = this._load(group).then(function () { + self._updateParentResIDs(group); + }); } return $.when(def).then(function () { return groupId; @@ -3400,6 +3405,26 @@ var BasicModel = AbstractModel.extend({ }); } }, + /** + * Updates the res_ids of the parent of a given element of type list. + * + * After some operations (e.g. loading more records, folding/unfolding a + * group), the res_ids list of an element may be updated. When this happens, + * the res_ids of its ancestors need to be updated as well. This is the + * purpose of this function. + * + * @param {Object} element + */ + _updateParentResIDs: function (element) { + var self = this; + if (element.parentID) { + var parent = this.localData[element.parentID]; + parent.res_ids = _.flatten(_.map(parent.data, function (dataPointID) { + return self.localData[dataPointID].res_ids; + })); + this._updateParentResIDs(parent); + } + }, /** * Helper method. Recursively traverses the data, starting from the element * record (or list), then following all relations. This is useful when one -- cgit v1.2.3