[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
This commit is contained in:
Xavier Bol (xbo)
2023-10-16 08:17:30 +02:00
parent 507b80a125
commit c143f1dca2
@@ -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]] || {};