summaryrefslogtreecommitdiff
path: root/addons/base/static/src/js/data.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-07-11 13:32:28 +0200
committerXavier Morel <xmo@openerp.com>2011-07-11 13:32:28 +0200
commit8ac948f36040f449ddae7d447a57cc7e7631d82b (patch)
treeeed9e9aec00acb3aeff35836054214582f3ab5f7 /addons/base/static/src/js/data.js
parentd8eba087d2ba566545084f4d270f5d635f3d5005 (diff)
[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
Diffstat (limited to 'addons/base/static/src/js/data.js')
-rw-r--r--addons/base/static/src/js/data.js46
1 files changed, 23 insertions, 23 deletions
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);
}
});