[FIX] web: pivot: clear sortedKeys when pruning

Due a typo, sortedKeys were not always cleared when pruning the
new trees after an update. Consequently the method _getTableRows could be
called on a inexisting sub tree. Here we simply fix the typo and a test.

opw-3584675

closes odoo/odoo#143714

X-original-commit: 3fa2d6e418daa2b1fa0df3c8d1ca643fac4cbaa2
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
Signed-off-by: Mathieu Duckerts-Antoine (dam) <dam@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2023-11-27 09:51:11 +00:00
parent 458d80b721
commit 2b80c8e647
2 changed files with 42 additions and 2 deletions
@@ -1518,7 +1518,7 @@ export class PivotModel extends Model {
const subTree = tree.directSubTrees.get(subTreeKey);
if (!oldTree.directSubTrees.has(subTreeKey)) {
subTree.directSubTrees.clear();
delete subTreeKey.sortedKeys;
delete subTree.sortedKeys;
} else {
const oldSubTree = oldTree.directSubTrees.get(subTreeKey);
this._pruneTree(subTree, oldSubTree);
@@ -3678,7 +3678,7 @@ QUnit.module("Views", (hooks) => {
'["Foo","Foo","Foo"]',
// origin headers
'["November 2016","December 2016","Variation","November 2016","December 2016"' +
',"Variation","November 2016","December 2016","Variation"]',
',"Variation","November 2016","December 2016","Variation"]',
// number of 'measures'
"1",
// number of 'origins'
@@ -5611,6 +5611,46 @@ QUnit.module("Views", (hooks) => {
}
);
QUnit.test("filter -> sort -> unfilter should not crash", async function (assert) {
await makeView({
type: "pivot",
resModel: "partner",
serverData,
arch: `
<pivot>
<field name="product_id" type="row"/>
<field name="bar" type="row"/>
</pivot>
`,
searchViewArch: `
<search>
<filter name="xphone" domain="[('product_id', '=', 37)]" />
</search>
`,
context: {
search_default_xphone: true,
},
});
assert.deepEqual(getFacetTexts(target), ["xphone"]);
assert.deepEqual(
[...target.querySelectorAll("tbody th")].map((el) => el.innerText),
["Total", "xphone", "Yes"]
);
assert.strictEqual(getCurrentValues(target), ["1", "1", "1"].join());
await click(target, ".o_pivot_measure_row");
await toggleSearchBarMenu(target);
await toggleMenuItem(target, "xphone");
assert.deepEqual(getFacetTexts(target), []);
assert.deepEqual(
[...target.querySelectorAll("tbody th")].map((el) => el.innerText),
["Total", "xphone", "Yes", "xpad"]
);
assert.strictEqual(getCurrentValues(target), ["4", "1", "1", "3"].join());
});
QUnit.test(
"no class 'o_view_sample_data' when real data are presented",
async function (assert) {