Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2227 Lượt xem

how can i hide contact from menu using python code 

or can control to hide or not contact via python 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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.

Tác giả Câu trả lời hay nhất

thank you for your reply,

can I prevent access for specific user ,


Ảnh đại diện
Huỷ bỏ

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.