[FIX] web: pivot correct context after reload
Open a pivot view with default filters automatically activating Disable those filters Change the groupBys on the rows and cols of the pivot Save your result as a favorite filter Before this commit, the filter did not contain the context information for columns groupby Also, the search view did not exploit the context of the new filter as it should be After this commit, the flow works as expected OPW 1913732 closes odoo/odoo#29415
This commit is contained in:
@@ -191,6 +191,10 @@ return Widget.extend({
|
||||
icon: 'fa-star',
|
||||
field: {
|
||||
get_context: function () {
|
||||
var filterContext = filter.context;
|
||||
if (typeof filter.context === 'string') {
|
||||
filterContext = pyeval.eval('context', filter.context);
|
||||
}
|
||||
var sortParsed = JSON.parse(filter.sort || "[]");
|
||||
var orderedBy = [];
|
||||
_.each(sortParsed, function (sort) {
|
||||
@@ -200,7 +204,7 @@ return Widget.extend({
|
||||
});
|
||||
});
|
||||
|
||||
return _.defaults({}, filter.context, {orderedBy : orderedBy});
|
||||
return _.defaults({}, filterContext, {orderedBy : orderedBy});
|
||||
},
|
||||
get_groupby: function () { return [filter.context]; },
|
||||
get_domain: function () { return filter.domain; }
|
||||
|
||||
@@ -191,7 +191,7 @@ var PivotModel = AbstractModel.extend({
|
||||
return {has_data: false};
|
||||
}
|
||||
return {
|
||||
colGroupBys: this.data.main_col.groupbys,
|
||||
colGroupBys: this.data.main_col.root.groupbys,
|
||||
context: this.data.context,
|
||||
domain: this.data.domain,
|
||||
fields: this.fields,
|
||||
@@ -200,7 +200,7 @@ var PivotModel = AbstractModel.extend({
|
||||
mainColWidth: this.data.main_col.width,
|
||||
measures: this.data.measures,
|
||||
rows: !isRaw && this._computeRows(),
|
||||
rowGroupBys: this.data.main_row.groupbys,
|
||||
rowGroupBys: this.data.main_row.root.groupbys,
|
||||
sortedColumn: this.data.sorted_column,
|
||||
};
|
||||
},
|
||||
@@ -266,22 +266,19 @@ var PivotModel = AbstractModel.extend({
|
||||
return this._loadData();
|
||||
}
|
||||
|
||||
var old_row_root = this.data.main_row.root;
|
||||
var old_col_root = this.data.main_col.root;
|
||||
var old_row = this.data.main_row;
|
||||
var old_col = this.data.main_col;
|
||||
return this._loadData().then(function () {
|
||||
var new_groupby_length;
|
||||
if (!('groupBy' in params) && !('pivot_row_groupby' in (params.context || {}))) {
|
||||
// we only update the row groupbys according to the old groupbys
|
||||
// if we don't have the key 'groupBy' in params. In that case,
|
||||
// we want to have the full open state for the groupbys.
|
||||
self._updateTree(old_row_root, self.data.main_row.root);
|
||||
new_groupby_length = self._getHeaderDepth(self.data.main_row.root) - 1;
|
||||
self.data.main_row.groupbys = old_row_root.groupbys.slice(0, new_groupby_length);
|
||||
self._updateTree(old_row.root, self.data.main_row.root);
|
||||
self._updateMainGroupBys(old_row, self.data.main_row);
|
||||
}
|
||||
|
||||
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_row_root.groupbys.slice(0, new_groupby_length);
|
||||
self._updateTree(old_col.root, self.data.main_col.root);
|
||||
self._updateMainGroupBys(old_col, self.data.main_col);
|
||||
});
|
||||
},
|
||||
/**
|
||||
@@ -644,9 +641,6 @@ var PivotModel = AbstractModel.extend({
|
||||
}
|
||||
}
|
||||
|
||||
this.data.main_row.groupbys = rowGroupBys;
|
||||
this.data.main_col.groupbys = colGroupBys;
|
||||
|
||||
main_row_header.other_root = main_col_header;
|
||||
main_col_header.other_root = main_row_header;
|
||||
|
||||
@@ -715,6 +709,19 @@ var PivotModel = AbstractModel.extend({
|
||||
this._traverseTree(root.children[i], f, arg1, arg2, arg3);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Updates the groupBys that the main[row | col] holds
|
||||
*
|
||||
* @private
|
||||
* @param {Object} old: The main abstract header before reload
|
||||
* @param {Object} main: The main abstract header after reload
|
||||
*
|
||||
*/
|
||||
_updateMainGroupBys: function (old, main) {
|
||||
var new_groupby_length = this._getHeaderDepth(main.root) - 1;
|
||||
var new_groupby_list = old.root.groupbys.slice(0, new_groupby_length);
|
||||
main.root.groupbys = new_groupby_list;
|
||||
},
|
||||
/**
|
||||
* @param {Object} old_tree
|
||||
* @param {Object} new_tree
|
||||
|
||||
@@ -825,6 +825,80 @@ QUnit.module('Views', {
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('correctly remove pivot_ keys from the context', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
this.data.partner.fields.amount = {string: "Amount", type: "float"};
|
||||
|
||||
// Equivalent to loading with default filter
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot>' +
|
||||
'<field name="date" interval="day" type="col"/>' +
|
||||
'<field name="amount" type="measure"/>' +
|
||||
'</pivot>',
|
||||
viewOptions: {
|
||||
context: {
|
||||
pivot_measures: ['foo'],
|
||||
pivot_column_groupby: ['customer'],
|
||||
pivot_row_groupby: ['product_id'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Equivalent to unload the filter
|
||||
var reloadParams = {
|
||||
context: {},
|
||||
};
|
||||
pivot.reload(reloadParams);
|
||||
|
||||
assert.deepEqual(pivot.getContext(), {
|
||||
pivot_column_groupby: ['customer'],
|
||||
pivot_measures: ['foo'],
|
||||
pivot_row_groupby: ['product_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
// Let's get rid of the rows groupBy
|
||||
pivot.$('tbody .o_pivot_header_cell_opened').click();
|
||||
|
||||
assert.deepEqual(pivot.getContext(), {
|
||||
pivot_column_groupby: ['customer'],
|
||||
pivot_measures: ['foo'],
|
||||
pivot_row_groupby: [],
|
||||
}, "context should be correct");
|
||||
|
||||
// And now, get rid of the col groupby
|
||||
pivot.$('thead .o_pivot_header_cell_opened').click();
|
||||
|
||||
assert.deepEqual(pivot.getContext(), {
|
||||
pivot_column_groupby: [],
|
||||
pivot_measures: ['foo'],
|
||||
pivot_row_groupby: [],
|
||||
}, "context should be correct");
|
||||
|
||||
pivot.$('tbody .o_pivot_header_cell_closed').click();
|
||||
pivot.$('.o_pivot_field_menu li[data-field=product_id] a').click();
|
||||
|
||||
assert.deepEqual(pivot.getContext(), {
|
||||
pivot_column_groupby: [],
|
||||
pivot_measures: ['foo'],
|
||||
pivot_row_groupby: ['product_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
pivot.$('thead .o_pivot_header_cell_closed').click();
|
||||
pivot.$('.o_pivot_field_menu li[data-field=customer] a').click();
|
||||
|
||||
assert.deepEqual(pivot.getContext(), {
|
||||
pivot_column_groupby: ['customer'],
|
||||
pivot_measures: ['foo'],
|
||||
pivot_row_groupby: ['product_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('correctly uses pivot_ keys from the context', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user