Defining Menus and Actions in Odoo18

ANURAG
September 30, 2024
menus-and-actions-in odoo18

And with each iteration, such as Odoo18 today, the customization options become more sophisticated: Companies small or large can now ensure a truly individualized experience. One of the big things that we do as part of this customization is defining a Menus and Actions in Odoo18 around menues and how users will navigate to access data. Any Odoo developer or administrator who is looking to improve the user interface and business flows will need to understand how to create these properly.

In this guide, you will learn how to define menus and actions in Odoo18 with a detailed breakdown of the steps and code used to achieve these functionalities.

Setting Up the Model

Instead of getting into menus and actions, let’s create a base model first. From there on we establish our menu and action configurations based on this model. We will use example model to work like a student data manager, lets crate this simple blog model for now.

from odoo import models, fields
class StudentData(models.Model):
    _name = "student.data"
    name = fields.Char(string="Name")
    class_name = fields.Char(string="Class")
    address = fields.Char(string="Address")

_name: Name of the model to be used within the Odoo system.

name: character field for the name of the studentlatesAutoresizingMaskIntoConstraints

class_name: class name is a character field.

address: A character field for student address.

This model will hold basic details about students, which in turn, will be the data that our menu and options can engage with.

Defining Actions

In odoo we model “Action” which represent how users interact with Data. They specify the views (list, form, kanban), and what is executed when a menu item becomes clicked.

An instance of an action that oversees student records is as follows:

<odoo>
    <data>
        <record id="action_student_record" model="ir.actions.act_window">
            <field name="name">Student Management</field>
            <field name="res_model">student.data</field>
            <field name="view_mode">tree,form</field>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                    Create a Data
                </p>
            </field>
        </record>
    </data>
</odoo>

action_student_record: This action’s special identification.
This indicates that it is a window action that opens a particular view (model=”ir.actions.act_window”).
name: The action’s name as it appears to the user.
View mode specifies the available views (form for individual record view, tree for list view), and res_model indicates the model to which this operation applies (student.data in this case).
Assistance: If there are no records, an HTML help message appears.
With the tree and form views, this action gives users the ability to manage student information and offers a simple interface for working with the data.
Making Menus: In Odoo, menus offer the framework for interacting with the system. Because they are hierarchical, you may arrange and clearly define the navigation experience.

Main menu and sub-menus for Student Management can be defined as as follows:

<odoo>
    <data>
        <menuitem id="student_menu_root"
                  name="Student Management"
                  sequence="10">
            <menuitem id="student_order_menu"
                      name="Students"
                      sequence="10">
                <menuitem id="menu_student_records"
                          name="Student Records"
                          action="action_student_record"
                          sequence="10"/>
            </menuitem>
        </menuitem>
    </data>
</odoo>

student_menu_root: The Student Management module‘s top-level menu.
sequence: Sets the menu display order, with lower numbers appearing first.
student_order_menu: Under the root menu, you can see a submenu called “Students.”
student records menu: a menu item that is connected to the action_student_record action under “Students.”
Users may simply access student records and go to the “Student Management” area thanks to this arrangement.

Expanding the Action Definitions and Menu

You may wish to include extra features in the module, like the ability to manage class records in addition to student records, in order to improve it.

To define an extra action and menu for class record management, follow these steps:

<odoo>
    <data>
        <!-- Action for Class Records -->
        <record id="action_class_record" model="ir.actions.act_window">
            <field name="name">Class Records</field>
            <field name="res_model">class.record</field>
            <field name="view_mode">tree,form</field>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                    Manage Classes
                </p>
            </field>
        </record>
        <!-- Menu for Class Records -->
        <menuitem id="class_menu"
                  name="Class Records"
                  action="action_class_record"
                  parent="student_order_menu"/>
    </data>
</odoo>

The action for maintaining class records defined by action_class_record.
The action’s applicable model specified by the value of res_model=”class.record”. class_menu: class.record A new menu item called “Class Records” has added to the “Students” menu.
This menu is a child of the “Students” menu, as shown by the parent=”student_order_menu” attribute.
This method of arranging menus ensures that all similar functionalities grouped together and gives users an intuitive, logical structure to browse.
Anyone who wants to modify Odoo18 to better suit their business processes must be able to define menus and actions. An interface that is easy to use and improves productivity can made by carefully arranging menus, defining actions, and setting up models.

We’ve gone over how to construct a basic model, make actions that decide how users interact with the data, and arrange these actions in a menu structure that is hierarchical in this guide. You may construct an effective and simple to use Odoo application by following these steps, regardless of the type of data you’re managing—student, class, or other. By using these tools, you can fully utilise Odoo18, tailoring it to your organization’s specific needs and delivering a smooth and efficient user experience.



"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

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