From 8ac948f36040f449ddae7d447a57cc7e7631d82b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 11 Jul 2011 13:32:28 +0200 Subject: [FIX] explicitly pass a list of fields to read_group instead of False read_group does not take inherited fields in its default list-of-fields-to-read, so if grouping on an inherited field it will blow up conversely, read_group can not aggregate on inherited numerical fields, so if it reads *all* the columns (including inherited) it will try to aggregate on fields it's not reading and that's also going to blow up. bzr revid: xmo@openerp.com-20110711113228-18mbcft9y2lf7ptm --- addons/base/static/src/js/data.js | 46 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'addons/base/static/src/js/data.js') 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); } }); -- cgit v1.2.3