summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-09-14 22:39:13 +0200
committerqsm-odoo <qsm@odoo.com>2017-09-14 23:48:55 +0200
commit031dc1d952837c0d9740e1caac1ab1d923863545 (patch)
tree13abe4e17c5f97d89bb9f57e019688d0769ffef9 /addons/web/static/src/js/views/basic/basic_model.js
parent76ad4e71a5f2f9a334e59a336447116739625ae2 (diff)
[REF] web: allow to perform a standalone read_group
Before this commit, asking the basic model for a 'read_group' operation was automatically followed by other operations to read groups content ('search_read', 'read', ...). This commit introduces an option to only perform a 'read_group'.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js16
1 files changed, 12 insertions, 4 deletions
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 90557eabba0..779073b51ed 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -2903,14 +2903,20 @@ var BasicModel = AbstractModel.extend({
* @param {Object} dataPoint some local resource
* @param {Object} [options]
* @param {string[]} [options.fieldNames] the fields to fetch for a record
+ * @param {boolean} [options.onlyGroups=false]
* @returns {Deferred}
*/
_load: function (dataPoint, options) {
+ if (options && options.onlyGroups &&
+ !(dataPoint.type === 'list' && dataPoint.groupedBy.length)) {
+ return $.when(dataPoint);
+ }
+
if (dataPoint.type === 'record') {
return this._fetchRecord(dataPoint, options);
}
if (dataPoint.type === 'list' && dataPoint.groupedBy.length) {
- return this._readGroup(dataPoint);
+ return this._readGroup(dataPoint, options);
}
if (dataPoint.type === 'list' && !dataPoint.groupedBy.length) {
return this._fetchUngroupedList(dataPoint);
@@ -3349,9 +3355,10 @@ var BasicModel = AbstractModel.extend({
* were open before.
*
* @param {Object} list valid resource object
+ * @param {Object} [options] @see _load
* @returns {Deferred<Object>} resolves to the fetched group object
*/
- _readGroup: function (list) {
+ _readGroup: function (list, options) {
var self = this;
var groupByField = list.groupedBy[0];
var rawGroupBy = groupByField.split(':')[0];
@@ -3413,10 +3420,11 @@ var BasicModel = AbstractModel.extend({
// restore the internal state of the group
delete self.localData[newGroup.id];
var updatedProps = _.omit(newGroup, 'limit', 'isOpen', 'offset', 'id');
- if (oldGroup.isOpen && newGroup.groupedBy.length) {
+ if (options && options.onlyGroups || oldGroup.isOpen && newGroup.groupedBy.length) {
// If the group is opened and contains subgroups,
// also keep its data to keep internal state of
// sub-groups
+ // Also keep data if we only reload groups' own data
delete updatedProps.data;
}
_.extend(oldGroup, updatedProps);
@@ -3429,7 +3437,7 @@ var BasicModel = AbstractModel.extend({
list.data.push(newGroup.id);
list.count += newGroup.count;
if (newGroup.isOpen && newGroup.count > 0) {
- defs.push(self._load(newGroup));
+ defs.push(self._load(newGroup, options));
}
});
return $.when.apply($, defs).then(function () {