[FIX] web: pivot: correctly save and restore groupbys on rows and cols
On a pivot view expand a field in column another one in row Then put a domain in the search view Save the whole thing (ir.filter) as favorite Before this commit, the ir.filter was not saved the right way when a domain was present (Let alone its restoration) This was because of - the internal default groupbys of the pivot model was not updated, and what we got in the params was overwritten by what existed before - a slight typo in the code made the row updated with the col values OPW 1835865 OPW 1829925 closes #24215
This commit is contained in:
@@ -250,6 +250,7 @@ var PivotModel = AbstractModel.extend({
|
||||
this.data.colGroupBys = params.context.pivot_column_groupby || this.data.colGroupBys;
|
||||
this.data.groupedBy = params.context.pivot_row_groupby || this.data.groupedBy;
|
||||
this.data.measures = this._processMeasures(params.context.pivot_measures) || this.data.measures;
|
||||
this.defaultGroupedBy = this.data.groupedBy.length ? this.data.groupedBy : this.defaultGroupedBy;
|
||||
}
|
||||
if ('domain' in params) {
|
||||
this.data.domain = params.domain;
|
||||
@@ -278,7 +279,7 @@ var PivotModel = AbstractModel.extend({
|
||||
|
||||
self._updateTree(old_col_root, self.data.main_col.root);
|
||||
new_groupby_length = self._getHeaderDepth(self.data.main_col.root) - 1;
|
||||
self.data.main_row.groupbys = old_col_root.groupbys.slice(0, new_groupby_length);
|
||||
self.data.main_row.groupbys = old_row_root.groupbys.slice(0, new_groupby_length);
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -960,4 +960,45 @@ QUnit.module('Views', {
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Row and column groupbys plus a domain', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot>' +
|
||||
'<field name="foo" type="measure"/>' +
|
||||
'</pivot>',
|
||||
});
|
||||
|
||||
// Set a column groupby
|
||||
pivot.$('thead .o_pivot_header_cell_closed').click();
|
||||
pivot.$('.o_field_selection li[data-field=customer] a').click();
|
||||
|
||||
// Set a Row groupby
|
||||
pivot.$('tbody .o_pivot_header_cell_closed').click();
|
||||
pivot.$('.o_pivot_field_menu li[data-field=product_id] a').click();
|
||||
|
||||
// Set a domain
|
||||
pivot.update({domain: [['product_id', '=', 41]]});
|
||||
|
||||
var expectedContext = {pivot_column_groupby: ['customer'],
|
||||
pivot_measures: ['foo'],
|
||||
pivot_row_groupby: ['product_id']};
|
||||
|
||||
// Mock 'save as favorite'
|
||||
assert.deepEqual(pivot.getContext(), expectedContext,
|
||||
'The pivot view should have the right context');
|
||||
|
||||
var $xpadHeader = pivot.$('tbody .o_pivot_header_cell_closed[data-original-title=Product]');
|
||||
assert.equal($xpadHeader.length, 1,
|
||||
'There should be only one product line because of the domain');
|
||||
|
||||
assert.equal($xpadHeader.text(), 'xpad',
|
||||
'The product should be the right one');
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
});});
|
||||
|
||||
Reference in New Issue
Block a user