Enable Dark Mode!
how-to-create-and-manage-a-new-user-menu-in-odoo-18.jpg
By: Ruksana P

How to Create & Manage a New User Menu in Odoo 18

Technical

The user menu in Odoo provides a streamlined interface for users to effortlessly access key functionalities, customize their settings, find support, dark mode, and onboarding, all within a single dropdown menu.

How to Create & Manage a New User Menu in Odoo 18-cybrosys

In this blog, we’ll add a menu option to activate developer mode. To do this, we can add new items to the user_menuitems registry.

Registries are like an organized collections of key/value pairs and serve as the main way to extend the Odoo web client. When the JavaScript framework needs to retrieve definitions for things like fields, views, actions, or services, it simply looks them up in the registry.

Categories of Registries:

1. Effect Register: Manages all the available visual and behavioral effects.

2. Formatter Register: Contains utility functions for formatting values, primarily for fields.

3. Parser Register: Houses functions responsible for interpreting or parsing values.

4. Main Component Register: Used for registering high-level components within the web client.

5. Service Register: Lists services that need to be activated in the system.

6. Systray Register: Controls the content displayed on the right side of the navigation bar.

7. User Menu Register: Handles the items shown in the user menu located at the top-right of the navbar.

Create JS file:

/** @odoo-module **/
import { registry } from "@web/core/registry";
import { browser } from "@web/core/browser/browser";
import { _t } from "@web/core/l10n/translation";
function debugItem(env) {
   const urlParams = new 
          URLSearchParams(window.location.search);
   urlParams.set('debug', '1');
   const debugURL = window.location.pathname + '?' +       
           urlParams.toString();
   return {
       id: "debug",
       type: "item",
       description: _t("Developer Mode"),
       href: debugURL,
       callback: () => {
           browser.open(debugURL, "_self");
       },
       sequence: 60,
   };
}
registry.category("user_menuitems").add("debug", debugItem)

The user menu registry (under the category user_menuitems) holds all the menu items that appear when the user menu (the navbar section with the user’s name in the top-right corner) is opened.

Each user menu item is defined by a function that takes the environment (env) and returns an object containing these details:

description: The text displayed for the menu item.

href: (optional) If provided and valid, the text will be placed inside an anchor (<a>) tag with the specified href link.

callback: The function that gets executed when the item is selected.

hide: (optional) Specifies whether the item should be hidden (default is false).

sequence: (optional) Specifies the order of the item relative to other items in the dropdown (default is 100).

Every time the user menu is opened, all functions defining the menu items are called.

Add in manifest

'assets': {
   'web.assets_backend': [        
      'sale_discount_limit/static/src/js/user_menu.js',
   ]
}

When the module is installed, the "Developer Mode" option appears in the user menu at the top-right corner of the navigation bar. Clicking this option enables debug mode.

How to Create & Manage a New User Menu in Odoo 18-cybrosys

The user menu simplifies navigation and enhances efficiency by offering easy access to important user-specific actions from the top-right corner of the interface.

To read more about How to Create & Manage a New User Menu in Odoo 17, refer to our blog How to Create & Manage a New User Menu in Odoo 17.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message