Odoo 16 – how to add a new menu item


Obtaining comprehensive Odoo technical tutorials can be a challenging task. Therefore, I have taken the initiative to share my knowledge and insights on Odoo development.

In this tutorial, I will explain how to add a new menu item within the “Inventory > Product” section. For a better understanding, please refer to the accompanying screenshot. Our objective is to introduce a new menu item labeled “Dummy Menu Item.”

As a general guideline, creating a new menu item in Odoo 16 necessitates two essential components:

  1. XML code for Menu item
  2. Action Record for that Menu item

To commence, we shall create our menuItem.xml file in our working module directory, which should be placed within the views folder. Please refer to the screenshot below.

In our XML code, we have defined attributes such as ‘id,’ ‘name,’ ‘action,’ ‘parent,’ and ‘sequence,’ all of which are self-explanatory. However, understanding how to obtain the ‘parent’ ID is crucial. In Odoo development, a significant portion of the work involves locating the necessary IDs, names, model files, and view files. Fortunately, Odoo’s user interface offers some helpful features for this purpose. If you have enabled the debug mode in Odoo, you can access these features.

Suppose, for instance, we need to create the new menu item within “Inventory > Product.” In that case, you can navigate to “Settings > Technical > Menu Items,” search for ‘product,’ and select ‘Inventory / Product.’ On this page, click the debug icon and then select ‘View Metadata.’ This action will reveal information as shown in the accompanying screenshot.

Here, we can identify the XML ID, which serves as the parent menu ID we will use in our menuItem.xml code.

Once we have completed this step, the next task is to create an action record associated with this menu item. We can add an action record just above our menu item definition.

Now, as you review the code above, you will notice that we have mentioned the model file. Consequently, we must create a model file for this menu item, as outlined below.

With these necessary components in place for our model, we must also update our access permission CSV file.

It is now the time to update our __manifest__.py file to include our new menu XML, permission CSV, and make the necessary updates to __init__.py for model imports.

Once you have upgraded your custom module, the new menu item will be added, and the associated action will be attached.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.