Skip to content
Permalink
Browse files

[FIX] web: pivot no result no remove groupbys

Since f8b38f6 dictionaries "groupbys" are the same object between the
pivot model instance and the headers menu.

But this causes an issue in 12.0 since when there is no results, the
headers menu groupbys is truncated and now being the same object, the
pivot model instance is also truncated.

So succedding search that find results would possibly have lost the
groupbys which is unexpected and breaks some 12.0 tests not expecting
it.

With this changeset, the groupbys are not truncated anymore.

Without the change, the added test fails with:

 Column groupby not lost after reload after empty results
  expected: { "pivot_column_groupby": [ "customer" ],
              "pivot_measures": [ "__count" ], "pivot_row_groupby": [] }
  result:   { "pivot_column_groupby": [], "pivot_measures":
              [ "__count" ], "pivot_row_groupby": [] }
closes #31644

Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
  • Loading branch information...
nle-odoo committed Mar 6, 2019
1 parent 7ef6557 commit ee5f1e277dd92cfcd1d980bc526989ed2b54a3b6
Showing with 35 additions and 15 deletions.
  1. +0 −15 addons/web/static/src/js/views/pivot/pivot_model.js
  2. +35 −0 addons/web/static/tests/views/pivot_tests.js
@@ -274,12 +274,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);
}
});
},
@@ -711,19 +709,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;
main.root.groupbys = old.root.groupbys;
main.root.groupbys.splice(new_groupby_length);
},
/**
* @param {Object} old_tree
* @param {Object} new_tree
@@ -1030,6 +1030,41 @@ 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 li[data-field=customer] a').click();

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

var expectedContext = {pivot_column_groupby: undefined,
pivot_measures: undefined,
pivot_row_groupby: undefined};
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]]});

var expectedContext = {pivot_column_groupby: ['customer'],
pivot_measures: ['__count'],
pivot_row_groupby: []};
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 ee5f1e2

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.