Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
2187 Zobrazení

how can i hide contact from menu using python code 

or can control to hide or not contact via python 

Avatar
Zrušit
Nejlepší odpověď

Hi Heba,

You can achieve it in multiple ways,


from odoo import tools


class Menu(models.Model):

_inherit = 'ir.ui.menu'


@api.model

@tools.ormcache('frozenset(self.env.user.groups_id.ids)', 'debug')

def _visible_menu_ids(self, debug=False):

menus = super(Menu, self)._visible_menu_ids(debug)

#To remove 'Contact' menu for all users

menus.discard(self.env.ref("contacts.menu_contacts").id)

return menus



Add contacts in depends in the 'manifest' file.


OR


Create a new user group and make the menu item accessible only to that specific group.



Restrict Menu Access



" rel="ugc">ir.ui.menu">



Make sure to replace 'module_name' with the actual name of your custom module where you defined the "Restrict Menu Access" group, Add contacts in depends in the manifest file.


Hope it Helps,
Kiran K

Avatar
Zrušit

Second method.

Create a new user group and make the menu item accessible only to that specific group.

<record id="restrict_menu_access" model="res.groups">
<field name="name">Restrict Menu Access</field>
</record>

<record id="contacts.menu_contacts" model="ir.ui.menu">
<field name="groups_id" eval="[(6, 0, [ref('module_name.restrict_menu_access')])]"/>
</record>

Make sure to replace 'module_name' with the actual name of your custom module where you defined the "Restrict Menu Access" group, Add contacts in depends in the manifest file.

Autor Nejlepší odpověď

thank you for your reply,

can I prevent access for specific user ,


Avatar
Zrušit

Yes, you can.
Check the free module,
https://apps.odoo.com/apps/modules/16.0/kg_hide_menu/
with this module, you can hide menu items for specific users.