From 2ba72fb2248665a4b06d1ea99452edc5acadc344 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 27 Jul 2017 16:03:10 +0200 Subject: [PATCH] [FIX] web: graph: reload with correct fields A traceback occurred when trying to reload a graph view with no groupBy in the searchview, because the array of fields to read given to the read_group RPC didn't contain the default groupBy field (Error "Fields in 'groupby' must appear in the list of fields to read"), e.g. in Sales > My Pipeline. --- .../static/src/js/views/graph/graph_model.js | 4 ++-- addons/web/static/tests/views/graph_tests.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/graph/graph_model.js b/addons/web/static/src/js/views/graph/graph_model.js index 8a7f5da6d5d..50e9f224697 100644 --- a/addons/web/static/src/js/views/graph/graph_model.js +++ b/addons/web/static/src/js/views/graph/graph_model.js @@ -114,13 +114,13 @@ return AbstractModel.extend({ * @returns {Deferred} */ _loadGraph: function () { - var fields = _.map(this.chart.groupedBy, function (groupBy) { + var groupedBy = this.chart.groupedBy.length ? this.chart.groupedBy : this.initialGroupBys; + var fields = _.map(groupedBy, function (groupBy) { return groupBy.split(':')[0]; }); if (this.chart.measure !== '__count__') { fields = fields.concat(this.chart.measure); } - var groupedBy = this.chart.groupedBy.length ? this.chart.groupedBy : this.initialGroupBys; return this._rpc({ model: this.modelName, method: 'read_group', diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js index 33b2fd8ffbd..c7d69b194ff 100644 --- a/addons/web/static/tests/views/graph_tests.js +++ b/addons/web/static/tests/views/graph_tests.js @@ -372,6 +372,30 @@ QUnit.module('Views', { }); }); + QUnit.test('reload graph with correct fields', function (assert) { + assert.expect(2); + + var graph = createView({ + View: GraphView, + model: 'foo', + data: this.data, + arch: '' + + '' + + '' + + '', + mockRPC: function (route, args) { + if (args.method === 'read_group') { + assert.deepEqual(args.kwargs.fields, ['product_id', 'foo'], + "should read the correct fields"); + } + return this._super.apply(this, arguments); + }, + }); + + graph.reload({groupBy: []}); + + graph.destroy(); + }); }); });