From 9739dbdd418fc095acb139b19b66914fd87649a0 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Wed, 30 Oct 2024 15:01:42 -0400 Subject: [PATCH] recursive_tree_view: make parent field active in views where it isn't if they're recursive --- recursive_tree_view/__manifest__.py | 2 +- recursive_tree_view/static/src/relational_model.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/recursive_tree_view/__manifest__.py b/recursive_tree_view/__manifest__.py index 1043a29..46e0388 100644 --- a/recursive_tree_view/__manifest__.py +++ b/recursive_tree_view/__manifest__.py @@ -19,7 +19,7 @@ # { "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 " "descendants of a parent record.", "category": "Technical", diff --git a/recursive_tree_view/static/src/relational_model.js b/recursive_tree_view/static/src/relational_model.js index 4a66f70..63b5c06 100644 --- a/recursive_tree_view/static/src/relational_model.js +++ b/recursive_tree_view/static/src/relational_model.js @@ -2,7 +2,7 @@ import {RelationalModel} from '@web/model/relational_model/relational_model'; 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, { // 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)) { config.domain = config.domain.concat([domain]); } + if (!(parentField in config.activeFields) || !config.activeFields[parentField]) { + config.activeFields[parentField] = makeActiveField() + } } return super._loadData(config); }, @@ -121,12 +124,13 @@ patch(RelationalModel.prototype, { findRecordInHierarchy(resId) { const records = this.root.records; + function findRecord(records) { for (let record of records) { if (record.resId === resId) { return record; } - if (record.children && record.children.length >0) { + if (record.children && record.children.length > 0) { const found = findRecord(record.children); if (found) { return found; @@ -134,6 +138,7 @@ patch(RelationalModel.prototype, { } } } + return findRecord(records) || null; } });