bemade-addons/recursive_tree_view/models/models.py
Marc Durepos 6bab956a54 [ADD] recursive_tree_view: new module for hierarchical models
Allows the viewing of hierarchical models (i.e. parent-child
relationships) directly in a tree view. Simply add the recursive
attribute to the tree tag with `recursive="1"` or `recursive="true"` or
`recursive="True"`.

Parent-child field is autodetected from the model based on the
_parent_name field which is standard in the Odoo ORM.

Currently there is no option for expanding all children, but this may be
added in future versions.
2024-10-30 12:11:55 -04:00

18 lines
634 B
Python

# models/parent_field_service.py
from odoo import models, api
class ParentFieldService(models.AbstractModel):
_name = "parent.field.service"
_description = "Service to retrieve parent field dynamically for any model"
@api.model
def get_parent_field(self, model_name):
"""
Returns the parent field name for the given model.
If _parent_name is not set, defaults to 'parent_id' if the field exists.
"""
Model = self.env[model_name] # Access the model dynamically
return Model._parent_name or (
"parent_id" if hasattr(Model, "parent_id") else None
)