DEV Community

Cover image for Odoo : Inherit base menu and add groups to it
Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

1

Odoo : Inherit base menu and add groups to it

While using Odoo development, you often get a use case to extend a base menu and add some custom group to it to restrict the access. Assuming the xml way of adding attributes to field, we may tend to do the same menu items in Odoo, sadly this will not work. Below is the proper way to extend and add user groups to a base menu.

For example we have menu item - purchase.menu_product_pricelist_action2_purchase - and we have a custom user group that is - custom_module.group_access_price_suppliers - now we need to add this new user group to the menu item. In order to do that we shall create a security.xml in our custom module and add below code to that

 <record id="purchase.menu_product_pricelist_action2_purchase" model="ir.ui.menu">
            <field name="groups_id" eval="[(6, 0, [ref('ambala.group_access_price_suppliers')])]"/>
        </record>
Enter fullscreen mode Exit fullscreen mode

This code snippet is from an XML file in an Odoo module, and it's used to define a menu item in the Odoo user interface. Let's break down the code:

xml
Copy code



: This tag is used to define a new record in Odoo's database. In this case, it's defining a record for a menu item.

id="purchase.menu_product_pricelist_action2_purchase": This assigns a unique identifier to the record. This ID is used to reference this record from other parts of the code.

model="ir.ui.menu": Specifies the Odoo model for which the record is being defined. In this case, it's defining a menu item (ir.ui.menu).

: This line sets the groups_id field of the menu item record. The groups_id field is used to specify which user groups have access to this menu item.

eval="[(6, 0, [ref('ambala.group_access_price_suppliers')])]: This part evaluates to a Python expression that defines the access groups for this menu item.
(6, 0, [ref('ambala.group_access_price_suppliers')]): This is a tuple with three elements:
6: This indicates that the operation is to replace the existing records with the given list.
0: This is the ID of the record to be replaced. Since it's 0, it means it's creating a new record.
[ref('ambala.group_access_price_suppliers')]: This is a reference to a user group defined in the system. ambala.group_access_price_suppliers likely represents a user group called "Price Suppliers" defined elsewhere in the code. It specifies that members of this user group will have access to this menu item.

if we want to just add the custom user group but keeping all the existing group then do the below

 <field name="groups_id" eval="[(4, ref('your_custom_group_id'))]"/>

Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

đź‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay