summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2020-07-29 12:41:01 +0000
committerNicolas Lempereur <nle@odoo.com>2020-08-14 12:31:50 +0000
commit7cf8f6f40e5769d2f22620ac425208c4ad9ae80b (patch)
tree17aad5a5f5159019ee57ea7743d8260554c0b5be /addons/web/static/src
parent43769580f5c1b4f71f85474e335e0d46b8afc43c (diff)
[FIX] web: pivot non-persistant on null value
In pivot view, a cell data is determined by his row/column key which are the value chain of field values to get to that row/column. If you had a grouping with value in a cell and then close the grouping, you could somehow get the old value back wrongly on next grouping operations. This happened because: - the key was computed based on the value (eg. for relational field the record ID) but without the field name. - succeeding read_group only fill existing values. eg. If on pivot view we had a salesperson with same ID as product category, if we closed salesperson grouping then opened product category grouping, we could possibly get the cell value to the product category that has the same ID as the salesperson. With this changeset, we clear the cell data corresponding to a grouping that has been closed. Added test without the fix would fail by displaying data of a previous read_group that should have been cleared inbetween. opw-2262306 closes #55129 closes odoo/odoo#55936 X-original-commit: f1df73adca4955561814d4b8e90a62d7d50c1c33 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_model.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js
index 3259d20c368..2a7afea689b 100644
--- a/addons/web/static/src/js/views/pivot/pivot_model.js
+++ b/addons/web/static/src/js/views/pivot/pivot_model.js
@@ -325,6 +325,7 @@ var PivotModel = AbstractModel.extend({
closeGroup: function (groupId, type) {
var groupBys;
var expandedGroupBys;
+ let keyPart;
var group;
var tree;
if (type === 'row') {
@@ -332,12 +333,35 @@ var PivotModel = AbstractModel.extend({
expandedGroupBys = this.data.expandedRowGroupBys;
tree = this.rowGroupTree;
group = this._findGroup(this.rowGroupTree, groupId[0]);
+ keyPart = 0;
} else {
groupBys = this.data.colGroupBys;
expandedGroupBys = this.data.expandedColGroupBys;
tree = this.colGroupTree;
group = this._findGroup(this.colGroupTree, groupId[1]);
+ keyPart = 1;
}
+
+ const groupIdPart = groupId[keyPart];
+ const range = groupIdPart.map((_, index) => index);
+ function keep(key) {
+ const idPart = JSON.parse(key)[keyPart];
+ return range.some(index => groupIdPart[index] !== idPart[index]) ||
+ idPart.length === groupIdPart.length;
+ }
+ function omitKeys(object) {
+ const newObject = {};
+ for (const key in object) {
+ if (keep(key)) {
+ newObject[key] = object[key];
+ }
+ }
+ return newObject;
+ }
+ this.measurements = omitKeys(this.measurements);
+ this.counts = omitKeys(this.counts);
+ this.groupDomains = omitKeys(this.groupDomains);
+
group.directSubTrees.clear();
delete group.sortedKeys;
var newGroupBysLength = this._getTreeHeight(tree) - 1;