跳至內容
選單
此問題已被標幟
2 回覆
2230 瀏覽次數

how can i hide contact from menu using python code 

or can control to hide or not contact via python 

頭像
捨棄
最佳答案

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

頭像
捨棄

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.

作者 最佳答案

thank you for your reply,

can I prevent access for specific user ,


頭像
捨棄

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.