DEV Community

Cover image for Odoo 17 : writing python conditions in XML
Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

1

Odoo 17 : writing python conditions in XML

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"/>
Enter fullscreen mode Exit fullscreen mode

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay