Skip to content
Permalink
Browse files

[FIX] web: keep col group by on 2nd reload+after 0 result

In 11.0 f8b38f6 improved the column group by managment when reloading
several times by having the same "groupbys" dictionaries between the
pivot model instance and the header menu.

This has been reverted in 12.0 (with c6e7adf) because the following
pivot tests failed with the change:
- 'rendering of pivot view with comparison'
- 'export data in excel with comparison'

The failure is because now that the "groupbys" dictionaries are the same
object, the truncated dictionary of a header truncate the one of the
model instance.

So if we search something that has no results, then something with
results, the groupbys could be lost.

This behavior has no reason to be and is changed in 11.0 with #31644,
this commit is the forward-port of f8b38f6 and #31644.

closes #31627

Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
  • Loading branch information...
nle-odoo committed Mar 6, 2019
1 parent a26496b commit b8d4fe6d386768a9b1b638358bc95a4a7575e3f9
Showing with 35 additions and 17 deletions.
  1. +2 −16 addons/web/static/src/js/views/pivot/pivot_model.js
  2. +33 −1 addons/web/static/tests/views/pivot_tests.js
@@ -440,12 +440,10 @@ var PivotModel = AbstractModel.extend({
// 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);
self._updateMainGroupBys(old_row, self.data.main_row);
}

if (!('pivot_column_groupby' in (params.context || {}))) {
self._updateTree(old_col.root, self.data.main_col.root);
self._updateMainGroupBys(old_col, self.data.main_col);
}
});
},
@@ -986,7 +984,8 @@ var PivotModel = AbstractModel.extend({
});

var index = 0;
var rowGroupBys = !_.isEmpty(this.data.groupedBy) ? this.data.groupedBy : this.initialRowGroupBys;
var rowGroupBys = !_.isEmpty(this.data.groupedBy) ? this.data.groupedBy : this.initialRowGroupBys.slice();
this.data.groupedBy = rowGroupBys;
var colGroupBys = this.data.colGroupBys;
var dataPoint, row, col, attrs, cell_value;
var main_row_header, main_col_header;
@@ -1118,19 +1117,6 @@ 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
@@ -1076,7 +1076,7 @@ QUnit.module('Views', {
pivot.destroy();
});

QUnit.skip('Reload, group by columns, reload', function (assert) {
QUnit.test('Reload, group by columns, reload', function (assert) {
assert.expect(2);

var pivot = createView({
@@ -1118,6 +1118,38 @@ QUnit.module('Views', {
pivot.destroy();
});

QUnit.test('Empty results keep groupbys', function (assert) {
assert.expect(2);

var pivot = createView({
View: PivotView,
model: "partner",
data: this.data,
arch: '<pivot/>',
});

// Set a column groupby
pivot.$('thead .o_pivot_header_cell_closed').click();
pivot.$('.o_field_selection .dropdown-item[data-field=customer]').click();

// Set a domain for empty results
pivot.update({domain: [['id', '=', false]]});

var expectedContext = {pivot_column_groupby: ['customer'],
pivot_measures: ['__count'],
pivot_row_groupby: []};
assert.deepEqual(pivot.getContext(), expectedContext,
'Column groupby not lost after empty results');

// Set a domain for not empty results
pivot.update({domain: [['product_id', '=', 37]]});

assert.deepEqual(pivot.getContext(), expectedContext,
'Column groupby not lost after reload after empty results');

pivot.destroy();
});

QUnit.test('correctly uses pivot_ keys from the context', function (assert) {
assert.expect(7);

0 comments on commit b8d4fe6

Please sign in to comment.
You can’t perform that action at this time.