Odoo 19 enhances its reputation as a highly adaptable business platform by offering even more refined tools for interface customization. At the heart of creating an intuitive user experience lies the effective configuration of menus and actions. These elements act as the roadmap for your application, guiding users through data and processes. For developers and system implementers, mastering their setup is key to building efficient and user-friendly Odoo environments.
This article provides a comprehensive overview of how to define and structure menus and actions in Odoo 19, complete with practical code examples.
Laying the Groundwork: The Data Model
Every feature in Odoo begins with a model that defines the data structure. Before creating navigation, we must establish the data users will interact with. Let's create a simple model to track project details.
from odoo import models, fields, api
class ProjectDetails(models.Model):
_name = "project.data"
_description = "Project Information"
name = fields.Char(string="Project Name", required=True)
reference_code = fields.Char(string="Reference Code")
start_date = fields.Date(string="Start Date")
status = fields.Selection(
selection=[('draft', 'Draft'), ('ongoing', 'Ongoing'), ('completed', 'Completed')],
string="Status",
default='draft'
)
- _name: This attribute defines the internal technical name for the model within the Odoo framework.
- _description: Provides a human-readable name that appears in the Odoo interface.
- Fields: The model includes various data types: a required character field (name), a standard text field (reference_code), a date field (start_date), and a selection field (status) with predefined options.
This model will serve as the foundation for the menus and actions we create next.
Defining Security Rules
Before we can interact with our model through the interface, we must define access rights. Odoo uses Access Control Lists to determine which user groups can read, write, create, or delete records. Create a CSV file to define these permissions: security/ir.model.access.csv.
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_project_data,access.project.data,model_project_data,base.group_user,1,1,1,1
This configuration grants all internal users full access to project data records. You can create multiple access rules for different user groups with varying permission levels.
Defining User Interactions: Configuring Actions
Actions are the engine behind menu items. They determine what happens when a user clicks on a menu, which data is displayed and in what format. In Odoo, a common type is the Window Action (ir.actions.act_window).
The following XML code defines an action to open our project data:
xml
<odoo>
<data>
<!-- Action to open the Project Data views -->
<record id="action_project_data" model="ir.actions.act_window">
<field name="name">Project Portfolio</field>
<field name="res_model">project.data</field>
<field name="view_mode">list,form,kanban</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Click here to create your first project.
</p>
</field>
</record>
</data>
</odoo>
- id: A unique XML identifier for this action.
- model: Specifies the type of action, in this case, a window action.
- name: The title displayed for the views opened by this action.
- res_model: The target model the action operates on (project.data).
- view_mode: The order and types of views available (list, form, and kanban).
- view_id: (Optional) Specifies a custom view to use as the default for the first view mode.
- help: Provides contextual guidance shown when no records are available.
Building the Navigation: Creating the Menu Structure
Menus organize actions into a clear hierarchy within the Odoo application. A well-designed menu structure is crucial for usability.
The XML below creates a main menu and places our action within it:
<odoo>
<data>
<!-- Top-level menu item -->
<menuitem id="main_menu_project"
name="Project Hub"
sequence="5"/>
<!-- Sub-menu within the main menu -->
<menuitem id="submenu_project_management"
name="Projects"
parent="main_menu_project"
sequence="10"/>
<!-- Menu item that triggers the action -->
<menuitem id="menu_item_project_data"
name="All Projects"
parent="submenu_project_management"
action="action_project_data"
sequence="15"/>
</data>
</odoo>
- id: A unique identifier for each menu item.
- name: The text displayed in the user interface.
- sequence: A numerical value that determines the order of items within their parent menu (lower numbers appear first).
- parent: (For sub-menus) The id of the parent menu item, defining the hierarchical structure.
- action: (For leaf menus) The id of the action that is launched when the user clicks the menu item.
Expanding the Structure: Adding Related Functionality
A complete application often requires multiple related models and menus. We can easily extend our structure. For instance, we could add a menu for project reports under the same main hub.
<odoo>
<data>
<!-- Action for Project Reports -->
<record id="action_project_report" model="ir.actions.act_window">
<field name="name">Project Analytics</field>
<field name="res_model">project.report</field>
<field name="view_mode">graph,pivot,tree</field>
</record>
<!-- Menu for Reports, grouped under the same main menu -->
<menuitem id="menu_item_project_reports"
name="Performance Reports"
parent="main_menu_project"
action="action_project_report"
sequence="20"/>
</data>
</odoo>
This approach keeps all project-related functionalities, both data entry and analysis, neatly organized under a single, intuitive "Project Hub" menu.
Configuring menus and actions is a fundamental skill for tailoring Odoo 19 to specific business workflows. The process involves a logical progression: first defining the data model, then creating the actions that interface with that data, and finally organizing those actions into a coherent menu hierarchy.
By following the principles outlined in this guide, you can transform the standard Odoo interface into a streamlined, purpose-built application that enhances user productivity and provides a seamless navigation experience. This powerful capability ensures that Odoo can be molded to fit the unique operational needs of any organization.
To read more about How to Define Menu & Actions in Odoo 18, refer to our blog How to Define Menu & Actions in Odoo 18.