Skip to Content
Menu
This question has been flagged
1 Reply
1967 Views

Hello, I have one custom module icon on my odoo 15 navigation bar here I want that only admin can view this icon the other user can not view this icon. how to do this. 

Avatar
Discard
Best Answer
  • Create An Empty module or you have any other module which depends on base
  • In Module inherit the model ir.ui.menu and override this function
from odoo import api, models

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

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
context = self._context or {}
if not self.env.user.has_group('base.group_system') and context.get('hide_non_admin_icons'):
args = [('icon', '=', False), ('groups_id', '=', False)] + args
return super(IrUiMenu, self).search(args, offset=offset, limit=limit, order=order, count=count)

  1. In your desired view, add the following line in the context to hide the icons:
  2. {'hide_non_admin_icons': True}


Avatar
Discard
Author

Thanks for your reply but the custom icon is added with an inherited template, in that case, how can I add context to it?