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(); + }); }); });