[FIX] web: allow grouping on fields not present in list view
[FIX] web,web_kanban: read_group: ensure read grouping fields bzr revid: chs@openerp.com-20131030180242-rxxlawffv13ll5s1
This commit is contained in:
parent
e2d6786bc1
commit
a237b0525d
|
@ -1345,22 +1345,29 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
|
|||
if (group.grouped_on) {
|
||||
var row_data = {};
|
||||
row_data[group.grouped_on] = group;
|
||||
var group_label = _t("Undefined");
|
||||
var group_column = _(self.columns).detect(function (column) {
|
||||
return column.id === group.grouped_on; });
|
||||
if (! group_column) {
|
||||
throw new Error(_.str.sprintf(
|
||||
_t("Grouping on field '%s' is not possible because that field does not appear in the list view."),
|
||||
group.grouped_on));
|
||||
}
|
||||
var group_label;
|
||||
try {
|
||||
group_label = group_column.format(row_data, {
|
||||
value_if_empty: _t("Undefined"),
|
||||
process_modifiers: false
|
||||
});
|
||||
} catch (e) {
|
||||
group_label = _.str.escapeHTML(row_data[group_column.id].value);
|
||||
if (group_column) {
|
||||
try {
|
||||
group_label = group_column.format(row_data, {
|
||||
value_if_empty: _t("Undefined"),
|
||||
process_modifiers: false
|
||||
});
|
||||
} catch (e) {
|
||||
group_label = _.str.escapeHTML(row_data[group_column.id].value);
|
||||
}
|
||||
} else {
|
||||
group_label = group.value;
|
||||
if (group_label instanceof Array) {
|
||||
group_label = group_label[1];
|
||||
}
|
||||
if (group_label === false) {
|
||||
group_label = _t('Undefined');
|
||||
}
|
||||
group_label = _.str.escapeHTML(group_label);
|
||||
}
|
||||
|
||||
// group_label is html-clean (through format or explicit
|
||||
// escaping if format failed), can inject straight into HTML
|
||||
$group_column.html(_.str.sprintf(_t("%s (%d)"),
|
||||
|
@ -1631,6 +1638,10 @@ var DataGroup = instance.web.Class.extend({
|
|||
},
|
||||
list: function (fields, ifGroups, ifRecords) {
|
||||
var self = this;
|
||||
if (!_.isEmpty(this.group_by)) {
|
||||
// ensure group_by fields are read.
|
||||
fields = _.unique((fields || []).concat(this.group_by));
|
||||
}
|
||||
var query = this.model.query(fields).order_by(this.sort).group_by(this.group_by);
|
||||
$.when(query).done(function (querygroups) {
|
||||
// leaf node
|
||||
|
|
|
@ -236,7 +236,11 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
|
|||
self.$buttons.find('.oe_alternative').toggle(self.grouped_by_m2o);
|
||||
self.$el.toggleClass('oe_kanban_grouped_by_m2o', self.grouped_by_m2o);
|
||||
var grouping_fields = self.group_by ? [self.group_by].concat(_.keys(self.aggregates)) : undefined;
|
||||
var grouping = new instance.web.Model(self.dataset.model, context, domain).query().group_by(grouping_fields);
|
||||
if (!_.isEmpty(grouping_fields)) {
|
||||
// ensure group_by fields are read.
|
||||
self.fields_keys = _.unique(self.fields_keys.concat(grouping_fields));
|
||||
}
|
||||
var grouping = new instance.web.Model(self.dataset.model, context, domain).query(self.fields_keys).group_by(grouping_fields);
|
||||
return self.alive($.when(grouping)).done(function(groups) {
|
||||
if (groups) {
|
||||
self.do_process_groups(groups);
|
||||
|
|
Loading…
Reference in New Issue