From c143f1dca2834873a5ad7e32609301913e93bf3c Mon Sep 17 00:00:00 2001 From: "Xavier Bol (xbo)" Date: Mon, 2 Oct 2023 17:52:57 +0200 Subject: [PATCH] [IMP] web: manage `parent_of` operator in domain in mockServer Before this commit, `child_of` operator is managed in the mockServer but not the `parent_of` one. This commit manages `parent_of` operator in mockServer to be able to find the record when the domain used contains that operator task-3376776 --- addons/web/static/tests/helpers/mock_server.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js index b0106a15742..8f17b09a51a 100644 --- a/addons/web/static/tests/helpers/mock_server.js +++ b/addons/web/static/tests/helpers/mock_server.js @@ -2198,6 +2198,21 @@ export class MockServer { }); } criterion = [criterion[0], "in", childIDs]; + } else if (criterion[1] === "parent_of") { + // 'parent_of' operator is not supported by domain.js, so we replace + // in by the 'in' operator (with the ids of parent and its ancestors) + const childID = criterion[2]; + const parentIDs = []; + const recordPerID = {}; + for (const record of records) { + recordPerID[record.id] = record; + } + let record = recordPerID[childID]; + while (record) { + parentIDs.push(record.id); + record = record.parent_id && recordPerID[record.parent_id]; + } + criterion = [criterion[0], "in", parentIDs]; } // In case of many2many field, if domain operator is '=' generally change it to 'in' operator const field = model.fields[criterion[0]] || {};