Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
2188 Tampilan

how can i hide contact from menu using python code 

or can control to hide or not contact via python 

Avatar
Buang
Jawaban Terbai

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
Buang

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.

Penulis Jawaban Terbai

thank you for your reply,

can I prevent access for specific user ,


Avatar
Buang

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.