diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2020-07-29 12:41:01 +0000 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2020-08-14 12:31:50 +0000 |
| commit | 7cf8f6f40e5769d2f22620ac425208c4ad9ae80b (patch) | |
| tree | 17aad5a5f5159019ee57ea7743d8260554c0b5be | |
| parent | 43769580f5c1b4f71f85474e335e0d46b8afc43c (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>
| -rw-r--r-- | addons/web/static/src/js/views/pivot/pivot_model.js | 24 | ||||
| -rw-r--r-- | addons/web/static/tests/views/pivot_tests.js | 31 |
2 files changed, 55 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; diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index ebcd2b69902..48e67e8641e 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -1511,6 +1511,37 @@ QUnit.module('Views', { pivot.destroy(); }); + QUnit.test('clear table cells data after closeGroup', async function (assert) { + assert.expect(2); + + const pivot = await createView({ + View: PivotView, + model: "partner", + data: this.data, + arch: '<pivot/>', + groupBy: ['product_id'], + }); + + await testUtils.dom.click(pivot.el.querySelector('thead .o_pivot_header_cell_closed')); + await testUtils.dom.click(pivot.el.querySelectorAll('.o_pivot_field_menu .dropdown-item[data-field="date"]')[0]); + + // close and reopen row groupings after changing value + this.data.partner.records.find(r => r.product_id === 37).date = '2016-10-27'; + await testUtils.dom.click(pivot.el.querySelector('tbody .o_pivot_header_cell_opened')); + await testUtils.dom.click(pivot.el.querySelector('tbody .o_pivot_header_cell_closed')); + await testUtils.dom.click(pivot.el.querySelector('.o_pivot_field_menu .dropdown-item[data-field="product_id"]')); + assert.strictEqual(pivot.el.querySelectorAll('.o_pivot_cell_value')[4].innerText, ''); // xphone December 2016 + + // invert axis, and reopen column groupings + await testUtils.dom.click(pivot.el.querySelector('.o_cp_buttons .o_pivot_flip_button')); + await testUtils.dom.click(pivot.el.querySelector('thead .o_pivot_header_cell_opened')); + await testUtils.dom.click(pivot.el.querySelector('thead .o_pivot_header_cell_closed')); + await testUtils.dom.click(pivot.el.querySelector('.o_pivot_field_menu .dropdown-item[data-field="product_id"]')); + assert.strictEqual(pivot.el.querySelectorAll('.o_pivot_cell_value')[3].innerText, ''); // December 2016 xphone + + pivot.destroy(); + }); + QUnit.test('correctly uses pivot_ keys from the context (at reload)', async function (assert) { assert.expect(8); |
