[FIX] web: Groupby not working on Pivot and Graph view
The groupby property was wrongly set in some cases: if a graph/pivot view is defined as a groupby on field F, but there is another groupby key G in the context, it will take F instead of G (at initial load).
This commit is contained in:
committed by
Géry Debongnie
parent
efd1585234
commit
b63e22f50e
@@ -60,12 +60,13 @@ return AbstractModel.extend({
|
||||
this.modelName = params.modelName;
|
||||
this.chart = {
|
||||
data: [],
|
||||
groupedBy: params.groupBys,
|
||||
groupedBy: params.groupedBy.length ? params.groupedBy : params.groupBys,
|
||||
measure: params.measure,
|
||||
mode: params.mode,
|
||||
domain: params.domain,
|
||||
context: params.context,
|
||||
};
|
||||
this.defaultGroupedBy = params.groupedBy;
|
||||
return this._loadGraph();
|
||||
},
|
||||
/**
|
||||
@@ -88,11 +89,7 @@ return AbstractModel.extend({
|
||||
this.chart.domain = params.domain;
|
||||
}
|
||||
if ('groupBy' in params) {
|
||||
if (!params.groupBy.length) {
|
||||
this.chart.groupedBy = this.initialGroupBys;
|
||||
} else {
|
||||
this.chart.groupedBy = params.groupBy;
|
||||
}
|
||||
this.chart.groupedBy = params.groupBy.length ? params.groupBy : this.defaultGroupedBy;
|
||||
}
|
||||
if ('measure' in params) {
|
||||
this.chart.measure = params.measure;
|
||||
|
||||
@@ -229,11 +229,12 @@ var PivotModel = AbstractModel.extend({
|
||||
this.data = {
|
||||
domain: params.domain,
|
||||
context: _.extend({}, session.user_context, params.context),
|
||||
groupedBy: params.rowGroupBys,
|
||||
groupedBy: params.groupedBy,
|
||||
colGroupBys: params.colGroupBys,
|
||||
measures: params.measures,
|
||||
sorted_column: {},
|
||||
};
|
||||
this.defaultGroupedBy = params.groupedBy;
|
||||
return this._loadData();
|
||||
},
|
||||
/**
|
||||
@@ -250,7 +251,7 @@ var PivotModel = AbstractModel.extend({
|
||||
this.data.domain = this.initialDomain;
|
||||
}
|
||||
if ('groupBy' in params) {
|
||||
this.data.groupedBy = params.groupBy;
|
||||
this.data.groupedBy = params.groupBy.length ? params.groupBy : this.defaultGroupedBy;
|
||||
}
|
||||
if (!this.data.has_data) {
|
||||
return this._loadData();
|
||||
|
||||
@@ -344,6 +344,34 @@ QUnit.module('Views', {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('correctly use group_by key from the context', function (assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(2);
|
||||
|
||||
var graph = createView({
|
||||
View: GraphView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<graph><field name="product_id" /></graph>',
|
||||
groupBy: ['color_id'],
|
||||
viewOptions: {
|
||||
context: {
|
||||
graph_measure: 'foo',
|
||||
graph_mode: 'line',
|
||||
},
|
||||
},
|
||||
});
|
||||
return concurrency.delay(0).then(function () {
|
||||
assert.strictEqual(graph.$('text:contains(xphone)').length, 0,
|
||||
'should not contain a text element with product in legend');
|
||||
assert.strictEqual(graph.$('text:contains(red)').length, 1,
|
||||
'should contain a text element with color in legend');
|
||||
graph.destroy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -825,4 +825,38 @@ QUnit.module('Views', {
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('correctly use group_by key from the context', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<pivot>' +
|
||||
'<field name="customer" type="col" />' +
|
||||
'<field name="foo" type="measure" />' +
|
||||
'</pivot>',
|
||||
groupBy: ['product_id'],
|
||||
});
|
||||
|
||||
assert.strictEqual(pivot.$('thead .o_pivot_header_cell_opened').length, 1,
|
||||
'column: should have one opened header');
|
||||
assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(First)').length, 1,
|
||||
'column: should display one closed header with "First"');
|
||||
assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(Second)').length, 1,
|
||||
'column: should display one closed header with "Second"');
|
||||
|
||||
assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_opened').length, 1,
|
||||
'row: should have one opened header');
|
||||
assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_closed:contains(xphone)').length, 1,
|
||||
'row: should display one closed header with "xphone"');
|
||||
assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_closed:contains(xpad)').length, 1,
|
||||
'row: should display one closed header with "xpad"');
|
||||
|
||||
assert.strictEqual(pivot.$('tbody tr:first td:nth(3)').text(), '32',
|
||||
'selected measure should be foo, with total 32');
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
});});
|
||||
|
||||
Reference in New Issue
Block a user