Hi everyone,
I'm struggling to dynamically hide/show columns in a list view (tree) in Odoo 19 based on a boolean flag set in the parent event form.
My Goal:
I have a custom module that inherits from event.event and event.registration.
If the event has is_internal_training = True, I want to show the employee_id and employee_number columns in the attendees registration list view.
If it is False, these columns should be completely hidden (column_invisible).
What works:
In the Form View of event.registration, using invisible="not is_internal_training" works flawlessly.
The Problem:
In the List View (tree), I cannot find the correct syntax for column_invisible to achieve this without breaking the framework.
If I try using parent.is_internal_training, OWL crashes with Name 'parent' is not defined when opening the list view independently (e.g., via the smart button or action menus).
If I try reading from the context using standard evaluation, the columns don't hide or I run into circular ParseError on the backend vs EvalError on the client.
My Code Setup:
1. Models (event_event.py):
from odoo import fields, models
classEventEvent(models.Model):
_inherit = 'event.event'
is_internal_training = fields.Boolean(string="Internal Training", default=False)2. Models (event_registration.py):
from odoo import fields, models
classEventRegistration(models.Model):
_inherit = 'event.registration'
employee_id = fields.Many2one('hr.employee', string="Employee")
employee_number = fields.Integer(related='employee_id.employee_number', string='Employee Number', store=True, readonly=True)
# Related field to expose the setting to the tree view
is_internal_training = fields.Boolean(
related='event_id.is_internal_training',
string='Is Internal Training',
readonly=True,
store=True
)
3. Main Event Form View (event_event_views.xml):
<xpath expr="//field[@name='tag_ids']"position="after"> <fieldname="is_internal_training"string="Internal Training"/>
</xpath>
4. Target Inherited Views (event_registration_views.xml):
<recordid="view_event_registration_form_inherit_custom"model="ir.ui.view"><fieldname="name">event.registration.form.inherit.custom.website.event</field><fieldname="model">event.registration</field><fieldname="inherit_id"ref="event.view_event_registration_form"/><fieldname="arch"type="xml"><xpathexpr="//field[@name='name']"position="before"><fieldname="employee_id"placeholder="Search employee..."invisible="not is_internal_training" /><fieldname="employee_number"invisible="not is_internal_training" /></xpath></field></record><recordid="view_event_registration_tree_inherit_custom"model="ir.ui.view"><fieldname="name">event.registration.tree.inherit.custom.website.event</field><fieldname="model">event.registration</field><fieldname="inherit_id"ref="event.view_event_registration_tree"/><fieldname="arch"type="xml"><xpathexpr="//field[@name='name']"position="before"><fieldname="employee_number"optional="show"column_invisible="context.get('is_internal_training', False)"/><fieldname="employee_id"optional="show"column_invisible="context.get('is_internal_training', False)"/></xpath></field></record>Since the attendees list view can be loaded inside the form but also globally (via smart buttons), what is the correct Odoo 19 way to dynamically evaluate column_invisible for this exact scenario using the context or the related field?
Thanks in advance!
Hello
Have you tried to pass the context from action?