From 524324ae4e4ec21b58d2d3a89340d1d36173b260 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 24 Jan 2014 13:59:44 +0100 Subject: [PATCH] [FIX] fixes two small issues concerning the groupby dates in graph view (addon web_graph) bzr revid: ged@openerp.com-20140124125944-wxl4zdya37pxdnqv --- .../web_graph/static/src/js/graph_widget.js | 24 +++++++++++-------- addons/web_graph/static/src/js/pivot_table.js | 6 ++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index d9fd73924ee..6d8dc185243 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -23,7 +23,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.bar_ui = options.bar_ui || 'group'; this.graph_view = options.graph_view || null; this.pivot_options = options; - this.important_fields = this.get_search_fields(); }, start: function() { @@ -44,6 +43,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ return this.model.call('fields_get', []).then(function (f) { self.fields = f; self.fields.__count = {field:'__count', type: 'integer', string:'Quantity'}; + self.important_fields = self.get_search_fields(); self.measure_list = self.get_measures(); self.add_measures_to_options(); self.pivot_options.row_groupby = self.create_field_values(self.pivot_options.row_groupby || []); @@ -69,6 +69,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ // this method gets the fields that appear in the search view, under the // 'Groupby' heading get_search_fields: function () { + var self = this; var search_view = openerp.client.action_manager.inner_widget.searchview; var groupbygroups = _(search_view.inputs).select(function (g) { @@ -77,13 +78,15 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ var filters = [].concat.apply([], _.pluck(groupbygroups, 'filters')); - return _.map(filters, function (filter) { - return { - field: py.eval(filter.attrs.context).group_by, - string: filter.attrs.string, - filter: filter - }; - }); + return _.uniq(_.map(filters, function (filter) { + console.log(filter); + var field = py.eval(filter.attrs.context).group_by, + raw_field = field.split(':')[0], + string = (field === raw_field) ? filter.attrs.string : self.fields[raw_field].string, + filter = (field === raw_field) ? filter : undefined; + + return { field: raw_field, string: string, filter: filter }; + }), false, function (filter) {return filter.field;}); }, // Extracts the integer/float fields which are not 'id' @@ -281,10 +284,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ if (!this.important_fields.length) { return; } - + var fields = _.map(this.important_fields, function (field) { - return {id: field.field, value: field.string, type:self.fields[field.field].type}; + return {id: field.field, value: field.string, type:self.fields[field.field.split(':')[0]].type}; }); + debugger; this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id})); $(event.target).after(this.dropdown); this.dropdown.css({position:'absolute', diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js index f47fcabc92e..d5c01765504 100644 --- a/addons/web_graph/static/src/js/pivot_table.js +++ b/addons/web_graph/static/src/js/pivot_table.js @@ -402,12 +402,12 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ value = attrs.value, grouped_on = attrs.grouped_on ? this.raw_field(attrs.grouped_on) : false; - if (grouped_on && this.fields[grouped_on].type === 'selection') { + if (value === false) { + group.attributes.value = 'undefined'; + } else if (grouped_on && this.fields[grouped_on].type === 'selection') { var selection = this.fields[grouped_on].selection, value_lookup = _.where(selection, {0:value}); group.attributes.value = value_lookup ? value_lookup[0][1] : 'undefined'; - } else if (value === false) { - group.attributes.value = 'undefined'; } else if (value instanceof Array) { group.attributes.value = value[1]; }