How to Define Menu & Actions in Odoo 16?

How to Define Menu & Actions in Odoo 16?

3 minutes, 23 seconds Read

In this blog, let us discuss how to define menus and actions in Odoo 16.  Odoo has a flexible ability to define Menus and Actions. First, we can see how to create a menu item in Odoo 16. So here we can just create a custom module, ‘Estate’.

[wpcc-iframe src=”https://cdn.iframe.ly/api/iframe?_cc_load_policy=true&click_to_play=1&playerjs=1&url=https%3A%2F%2Fyoutu.be%2FMV_4nyN5hUU&key=7c1a8a6660ba8578ffa7a2b730770df2″ style=”top: 0; left: 0; width: 100%; height: 100%; position: absolute; border: 0;” allowfullscreen=”” scrolling=”no” allow=”autoplay *; accelerometer *; clipboard-write *; encrypted-media *; gyroscope *; picture-in-picture *; web-share *;”]

how-to-define-menu-and-actions-in-odoo-16-1

This is a custom module. Then, we can see how we can add the first menu.       

        <menuitem id="estate_menu_root" name="Estate"
        sequence="10"/>

We need to create a menu item record as shown below. Here we can specify an ID and name of the specific menu item in the menu item tag. This name will appear in the UI as a menu item, and we can also assign a serial number to our particular menu item.

how-to-define-menu-and-actions-in-odoo-16-2

Here, in the image above, we can see the Menu “Advertising” and another menu property under advertisement. Then we can discuss how we can create a menu like this.

<menuitem id="estate_menu_root" name="Estate"
       sequence="10"/>
   <menuitem id="estate_first_menu_root" name="Advertisement"
       parent='estate_menu_root' sequence="8"/>

The code goes like this, That is we have also discussed before a menu item taken id and name and along with that we have also specified the parent attribute inside this menu item tag, since the First menu item that is here the menu “Estate” is the parent of the second menu item that is “Advertisement” , so here we specified the id of first menu item is inside the parent attribute of second menu.

how-to-define-menu-and-actions-in-odoo-16-3

While we have clicked the second menu, we can have another menu called “Property”, Let’s see how we can create a menu under another menu.

<menuitem id="estate_second_menu_root" name="Properties"
         parent='estate_first_menu_root' sequence="9"
         action="estate_property_action"/>

The code of the menu item is mentioned above, it also take the id, name, parent, the parent will be the second menu item and then added the sequence attributes. In this case, we can also specify another attribute which is actions. Inside the action attribute, we need to specify which action we need to perform while picking the menu item.

how-to-define-menu-and-actions-in-odoo-16-4

While clicking the menu iteitem, goes to a tree view of the model “estate.property”.

Here I’ve already added a model and created tree view and form view. Then we need to define the act window record of the particular model.

<record id="estate_property_action" model="ir.actions.act_window">
   <field name="name">Properties</field>
   <field name="type"> ir.actions.act_window"</field>
   <field name="res_model">estate.property</field>
   <field name="view_mode">tree,form</field>
</record>

will be like this. So window action is created in template ir.actions.act_window, here we can specify id of general record act_window, in template name field we will specify name of record act_window , and in the type field we can specify the ir action.

act_window , in the rest of the model fields we will specify the model whose view should open when this particular menu item is clicked, then in the view mode field define the specific view which should open when a particular menu item is clicked – click .The id of Actions is putting the action attribute of inside the menu item. This way, we can provide actions for a menu item.

Then we can see the UI. While clicking the menu item, it will open the tree view. 

how-to-define-menu-and-actions-in-odoo-16-5

While clicking on one particular line item, it will open its particular form view.

how-to-define-menu-and-actions-in-odoo-16-6

In this way, we can define or create the menu items and actions in Odoo 16.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *