[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.
This commit is contained in:
Aaron Bohy
2017-07-28 09:27:31 +02:00
parent 3b3f6f04af
commit 2ba72fb224
2 changed files with 26 additions and 2 deletions
@@ -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',
@@ -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: '<graph>' +
'<field name="product_id" type="row"/>' +
'<field name="foo" type="measure"/>' +
'</graph>',
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();
});
});
});