[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
This commit is contained in:
parent
d8eba087d2
commit
8ac948f360
|
@ -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):
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1074,18 +1074,23 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
|
|||
var self = this;
|
||||
var $element = $('<tbody>');
|
||||
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;
|
||||
},
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue