diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 1179eb37d42..d60ed63ac4f 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -526,12 +526,12 @@ class DataSet(openerpweb.Controller): class DataGroup(openerpweb.Controller): _cp_path = "/base/group" @openerpweb.jsonrequest - def read(self, request, model, group_by_fields, domain=None): + def read(self, request, model, fields, group_by_fields, domain=None): Model = request.session.model(model) context, domain = eval_context_and_domain(request.session, request.context, domain) return Model.read_group( - domain or [], False, group_by_fields, 0, False, + domain or [], fields, group_by_fields, 0, False, dict(context, group_by=group_by_fields)) class View(openerpweb.Controller): diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index 1eb9c0f0a0d..534fd356f06 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -120,29 +120,25 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend( aggregates: aggregates }; }, - fetch: function () { + fetch: function (fields) { // internal method var d = new $.Deferred(); var self = this; - // disable caching for now, not sure what I should do there - if (false && this.groups) { - d.resolveWith(this, [this.groups]); - } else { - this.rpc('/base/group/read', { - model: this.model, - context: this.context, - domain: this.domain, - group_by_fields: this.group_by - }, function () { }).then(function (response) { - var data_groups = _(response).map( - _.bind(self.transform_group, self)); - self.groups = data_groups; - d.resolveWith(self, [data_groups]); - }, function () { - d.rejectWith.apply(d, self, [arguments]); - }); - } + this.rpc('/base/group/read', { + model: this.model, + context: this.context, + domain: this.domain, + fields: _.uniq(this.group_by.concat(fields)), + group_by_fields: this.group_by + }, function () { }).then(function (response) { + var data_groups = _(response).map( + _.bind(self.transform_group, self)); + self.groups = data_groups; + d.resolveWith(self, [data_groups]); + }, function () { + d.rejectWith.apply(d, [self, arguments]); + }); return d.promise(); }, /** @@ -163,10 +159,14 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend( * records have for the current ``grouped_on`` field name). * ``aggregates`` * a mapping of other aggregation fields provided by ``read_group`` + * + * @param {Array} fields the list of fields to aggregate in each group, can be empty + * @param {Function} ifGroups function executed if any group is found (DataGroup.group_by is non-null and non-empty), called with a (potentially empty) list of groups as parameters. + * @param {Function} ifRecords function executed if there is no grouping left to perform, called with a DataSet instance as parameter */ - list: function (ifGroups, ifRecords) { + list: function (fields, ifGroups, ifRecords) { var self = this; - this.fetch().then(function (group_records) { + this.fetch(fields).then(function (group_records) { ifGroups(_(group_records).map(function (group) { var child_context = _.extend({}, self.context, group.__context); return _.extend( @@ -195,7 +195,7 @@ openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend( init: function (session, model, domain, context, level) { this._super(session, model, domain, context, null, level); }, - list: function (ifGroups, ifRecords) { + list: function (fields, ifGroups, ifRecords) { ifRecords(_.extend( new openerp.base.DataSetSearch(this.session, this.model), {domain: this.domain, context: this.context})); @@ -215,7 +215,7 @@ openerp.base.StaticDataGroup = openerp.base.GrouplessDataGroup.extend( init: function (dataset) { this.dataset = dataset; }, - list: function (ifGroups, ifRecords) { + list: function (fields, ifGroups, ifRecords) { ifRecords(this.dataset); } }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index c4aea837a4f..60d9e3b552c 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -1074,18 +1074,23 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr var self = this; var $element = $(''); this.elements = [$element[0]]; - this.datagroup.list(function (groups) { - $element[0].appendChild( - self.render_groups(groups)); - if (post_render) { post_render(); } - }, function (dataset) { - self.render_dataset(dataset).then(function (list) { - self.children[null] = list; - self.elements = - [list.$current.replaceAll($element)[0]]; + + this.datagroup.list( + _(this.view.visible_columns).chain() + .filter(function (column) { return column.tag === 'field' }) + .pluck('name').value(), + function (groups) { + $element[0].appendChild( + self.render_groups(groups)); if (post_render) { post_render(); } + }, function (dataset) { + self.render_dataset(dataset).then(function (list) { + self.children[null] = list; + self.elements = + [list.$current.replaceAll($element)[0]]; + if (post_render) { post_render(); } + }); }); - }); return $element; }, /**