recursive_tree_view: make parent field active in views where it isn't if they're recursive

This commit is contained in:
Marc Durepos 2024-10-30 15:01:42 -04:00
parent da802131e8
commit 9739dbdd41
2 changed files with 8 additions and 3 deletions

View file

@ -19,7 +19,7 @@
# #
{ {
"name": "Recursive Tree View", "name": "Recursive Tree View",
"version": "17.0.0.0.1", "version": "17.0.0.0.2",
"summary": "Adds the ability to mark a tree view as recursive, to expand " "summary": "Adds the ability to mark a tree view as recursive, to expand "
"descendants of a parent record.", "descendants of a parent record.",
"category": "Technical", "category": "Technical",

View file

@ -2,7 +2,7 @@
import {RelationalModel} from '@web/model/relational_model/relational_model'; import {RelationalModel} from '@web/model/relational_model/relational_model';
import {patch} from '@web/core/utils/patch'; import {patch} from '@web/core/utils/patch';
import {getFieldsSpec, getBasicEvalContext} from "@web/model/relational_model/utils"; import {getFieldsSpec, getBasicEvalContext, makeActiveField} from "@web/model/relational_model/utils";
patch(RelationalModel.prototype, { patch(RelationalModel.prototype, {
// TODO: Modify the domain to include only records with parentField = False in the root search // TODO: Modify the domain to include only records with parentField = False in the root search
@ -26,6 +26,9 @@ patch(RelationalModel.prototype, {
if (!(domain in config.domain)) { if (!(domain in config.domain)) {
config.domain = config.domain.concat([domain]); config.domain = config.domain.concat([domain]);
} }
if (!(parentField in config.activeFields) || !config.activeFields[parentField]) {
config.activeFields[parentField] = makeActiveField()
}
} }
return super._loadData(config); return super._loadData(config);
}, },
@ -121,12 +124,13 @@ patch(RelationalModel.prototype, {
findRecordInHierarchy(resId) { findRecordInHierarchy(resId) {
const records = this.root.records; const records = this.root.records;
function findRecord(records) { function findRecord(records) {
for (let record of records) { for (let record of records) {
if (record.resId === resId) { if (record.resId === resId) {
return record; return record;
} }
if (record.children && record.children.length >0) { if (record.children && record.children.length > 0) {
const found = findRecord(record.children); const found = findRecord(record.children);
if (found) { if (found) {
return found; return found;
@ -134,6 +138,7 @@ patch(RelationalModel.prototype, {
} }
} }
} }
return findRecord(records) || null; return findRecord(records) || null;
} }
}); });