Managing Buttons Easily with IDs in Odoo 15 and Above

Starting from Odoo 15, a handy feature was introduced that makes it much easier for developers to work with buttons in views  the id attribute for buttons. This simple addition has made a big difference in how we can manage and customize buttons in the UI.


In previous versions of Odoo, it was often tricky to uniquely identify buttons(mostly we accessed using Index), especially when there were multiple buttons with the same name or similar functionality. For example, in the Sale Order form view, there might be two buttons with the same label, without unique IDs, it became cumbersome to target and update a specific button through inheritance or JavaScript.


With the introduction of the id attribute for buttons, Odoo allows us to uniquely tag each button, enabling easier customization. Once an ID is set, you can refer to it directly in XML or JS code, making it much simpler to:


Here is an eg from sale order having same function name and we can change its parameters by uniquely locating its id




<xpath expr="//button[@id=send_profoma]" position="attributes">

    <attribute name="string">Send</attribute>

</xpath>



This small but powerful change significantly improves the developer experience in Odoo. By simply adding an id to your buttons, you can write cleaner, more maintainable code, and avoid conflicts or confusion when dealing with buttons that may otherwise look identical.

Share this post
Tags
Archive
Odoo Community vs. Enterprise Edition: A Comprehensive Comparison