(#116) How to Hide Specific Menus for Individual Users in Odoo 18

(#116) How to Hide Specific Menus for Individual Users in Odoo 18

The customized ERP system Odoo 18 provides businesses with substantial management capabilities to operate their operations effectively. The business needs security features alongside better user experience by limiting menu access for different types of users in specific operational scenarios. This text provides step-by-step instructions for hiding particular menus for specific users within Odoo 18 by utilizing Access Control Lists (ACLs) and record rules and custom module development procedures.


Why Hide Menus for Specific Users?

The purpose of hiding menus for specific users in Odoo 18 becomes necessary due to multiple essential reasons.

  • Security: Specific user access security functions work to block unauthorized persons from accessing sensitive information.
  • User Experience: The interface needs simplification through an interface showing relevant menus for users.
  • Compliance: The program limits specified functions to users according to their assigned organizational roles.
  • Efficiency: Reduce confusion and streamline operations.

The following section explores different techniques that achieve this task within Odoo 18.


Method 1: Using Access Control Lists (ACLs)

Access Control Lists (ACLs) are a fundamental feature in Odoo that allows you to control access to models and menus based on user groups.

Steps to Restrict Menus Using ACLs

1. Navigate to the Settings Module

  • Go to Settings → Users & Companies → Groups.

2. Create a New User Group

  • Click on Create, provide a meaningful group name (e.g., "Restricted User"), and save.

3. Assign Users to the Group

  • In the Users tab, add the users who should have restricted access.

4. Modify ACLs

  • Go to Settings Technical Access Control Lists.
  • Create a new ACL restricting access to the menu’s related model.
  • Set the access rights for the group created earlier (No Read, Write, Create, or Delete access as needed).

5. Save and Apply Changes

  • Restart Odoo if necessary to ensure the changes take effect.


Method 2: Using Record Rules

Record rules allow you to dynamically filter access to specific records, including menus.

Steps to Hide Menus Using Record Rules

1. Go to Settings > Technical > Record Rules

2. Create a New Record Rule

  • Assign a meaningful name (e.g., "Restrict Menu Access").
  • Choose the model related to the menu.
  • Apply a domain filter like:

[('id', 'not in', [menu_id])]        

  • Assign the rule to the restricted user group.

3. Save the Changes

4. Test with a Restricted User


Method 3: Hiding Menus Using XML and User Groups

For advanced customization, you can modify Odoo's XML files to hide menus based on user groups.

Steps to Hide Menus in XML

1. Create a Custom Module

  • If you don't already have a custom module, create one using the following structure:

my_module/
├── models/
├── views/
├── security/
├── __init__.py
├── __manifest__.py        

2. Define a User Group in Security File

  • Add a security group in security/groups.xml :

<record id="group_restricted_user" model="res.groups">
    <field name="name">Restricted User</field>
</record>        

3. Modify the Menu XML File

  • Open views/menu.xml and add:

<menuitem id="menu_specific" name="Hidden Menu" groups="base.group_user, group_restricted_user"/>        

  • Replace menu_specific with the actual menu ID you want to hide.

4. Update and Restart Odoo

  • Install or upgrade your module and restart Odoo.


Method 4: Using Python Code in Custom Modules

For developers, using Python code to hide menus dynamically is a powerful approach.

Steps to Implement Dynamic Menu Hiding in Python

1. Open Your Custom Module and Edit models.py

Add the following code:

from odoo import models, api

class HideMenu(models.Model):
    _inherit = 'ir.ui.menu'

    @api.model
    def _filter_visible_menus(self, menu_ids):
        user = self.env.user
        restricted_menus = [menu_id for menu_id in menu_ids if not user.has_group('my_module.group_restricted_user')]
        return restricted_menus        

2. Restart Odoo and Test

  • Apply changes and verify that restricted users cannot see specific menus.


Testing and Validation

Once you implement any of these methods, it’s important to test the restrictions thoroughly:

  1. Log in as a Restricted User
  2. Verify That Hidden Menus Are Not Visible
  3. Ensure Functionality for Admin Users
  4. Check Logs for Errors
  5. Apply Fixes as Needed


Conclusion

For effective user role management in Odoo 18 the process of menu hiding for individual users represents a fundamental step. You can maintain menu access only for approved users through the combination of ACLs and record rules and XML modification and Python scripting. Select the most suitable methodology from among ACLs, record rules and XML modifications and Python scripting based on technological capabilities along with your project specifications.

要查看或添加评论,请登录

Arsalan Yasin的更多文章