In Odoo 17, it's possible to write Python conditions directly in the XML view. For instance, if we have a field named 'can_edit_shop_orders' in our model and we need to dynamically show/hide another field based on its value, here's how we can achieve that. Let's assume 'can_edit_shop_orders' is a boolean field, and we want to control the visibility of another field named 'shop_orders' based on its value.
<field name="shop_orders" string="Shop Orders" readonly="not can_edit_shop_orders"/>
<field name="can_edit_shop_orders" invisible= "1"/>
As demonstrated, Python conditions can be embedded within the XML structure. It's crucial to note that the boolean field must be included in the view itself, even if it's hidden, to avoid errors thrown by Odoo.
Top comments (0)