[FIX] correctly use the col group by instead of groupby when reading the context and initializing a graph view (addon web_graph)

bzr revid: ged@openerp.com-20140207135339-ohrjh6uvu22tjavh
This commit is contained in:
Gery Debongnie
2014-02-07 14:53:39 +01:00
parent 79caa8e186
commit 88b7511f68
+11 -9
View File
@@ -50,7 +50,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
var field_name = field.attrs.name;
if (_.has(field.attrs, 'interval')) {
field_name = field.attrs.name + ':' + field.attrs.interval;
}
}
if (_.has(field.attrs, 'type')) {
switch (field.attrs.type) {
case 'row':
@@ -78,14 +78,14 @@ instance.web_graph.GraphView = instance.web.View.extend({
do_search: function (domain, context, group_by) {
var self = this,
col_group_by = context.col_group_by || this.get_groupbys_from_searchview('ColGroupBy', 'col_group_by');
col_group_by = this.extract_groupby('col_group_by', context) || [];
if (!this.graph_widget) {
if (group_by.length) {
this.widget_config.row_groupby = group_by;
}
if (col_group_by.length) {
this.widget_config.col_groupby = group_by;
this.widget_config.col_groupby = col_group_by;
}
this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config);
this.graph_widget.appendTo(this.$el);
@@ -101,16 +101,18 @@ instance.web_graph.GraphView = instance.web.View.extend({
this.graph_widget.set(domain, group_by, col_group_by);
},
extract_groupby: function (cat_field, context) {
context = (_.isString(context)) ? py.eval(context) : context;
return context[cat_field];
},
get_groupbys_from_searchview: function (cat_name, cat_field) {
var facet = this.search_view.query.findWhere({category:cat_name}),
var self=this,
facet = this.search_view.query.findWhere({category:cat_name}),
groupby_list = facet ? facet.values.models : [];
return _.map(groupby_list, function (g) {
var context = g.attributes.value.attrs.context;
if (_.isString(context)) {
return py.eval(context).group_by;
} else {
return context[cat_field];
}
return self.extract_groupby(cat_field, context);
});
},