[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) {
|
if (group.grouped_on) {
|
||||||
var row_data = {};
|
var row_data = {};
|
||||||
row_data[group.grouped_on] = group;
|
row_data[group.grouped_on] = group;
|
||||||
|
var group_label = _t("Undefined");
|
||||||
var group_column = _(self.columns).detect(function (column) {
|
var group_column = _(self.columns).detect(function (column) {
|
||||||
return column.id === group.grouped_on; });
|
return column.id === group.grouped_on; });
|
||||||
if (! group_column) {
|
if (group_column) {
|
||||||
throw new Error(_.str.sprintf(
|
try {
|
||||||
_t("Grouping on field '%s' is not possible because that field does not appear in the list view."),
|
group_label = group_column.format(row_data, {
|
||||||
group.grouped_on));
|
value_if_empty: _t("Undefined"),
|
||||||
}
|
process_modifiers: false
|
||||||
var group_label;
|
});
|
||||||
try {
|
} catch (e) {
|
||||||
group_label = group_column.format(row_data, {
|
group_label = _.str.escapeHTML(row_data[group_column.id].value);
|
||||||
value_if_empty: _t("Undefined"),
|
}
|
||||||
process_modifiers: false
|
} else {
|
||||||
});
|
group_label = group.value;
|
||||||
} catch (e) {
|
if (group_label instanceof Array) {
|
||||||
group_label = _.str.escapeHTML(row_data[group_column.id].value);
|
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
|
// group_label is html-clean (through format or explicit
|
||||||
// escaping if format failed), can inject straight into HTML
|
// escaping if format failed), can inject straight into HTML
|
||||||
$group_column.html(_.str.sprintf(_t("%s (%d)"),
|
$group_column.html(_.str.sprintf(_t("%s (%d)"),
|
||||||
|
@ -1631,6 +1638,10 @@ var DataGroup = instance.web.Class.extend({
|
||||||
},
|
},
|
||||||
list: function (fields, ifGroups, ifRecords) {
|
list: function (fields, ifGroups, ifRecords) {
|
||||||
var self = this;
|
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);
|
var query = this.model.query(fields).order_by(this.sort).group_by(this.group_by);
|
||||||
$.when(query).done(function (querygroups) {
|
$.when(query).done(function (querygroups) {
|
||||||
// leaf node
|
// 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.$buttons.find('.oe_alternative').toggle(self.grouped_by_m2o);
|
||||||
self.$el.toggleClass('oe_kanban_grouped_by_m2o', 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_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) {
|
return self.alive($.when(grouping)).done(function(groups) {
|
||||||
if (groups) {
|
if (groups) {
|
||||||
self.do_process_groups(groups);
|
self.do_process_groups(groups);
|
||||||
|
|
Loading…
Reference in New Issue