61 lines
2.7 KiB
Python
61 lines
2.7 KiB
Python
from odoo import models, api
|
|
|
|
class IrUiMenu(models.Model):
|
|
_inherit = 'ir.ui.menu'
|
|
|
|
def _filter_visible_menus(self):
|
|
res = super()._filter_visible_menus()
|
|
user = self.env.user
|
|
|
|
# Avoid restricting the superuser (id = 1) or public/portal users
|
|
if user.id == 1 or user.share:
|
|
return res
|
|
|
|
is_pos = user.is_pos_user
|
|
is_kitchen = user.is_kitchen_user
|
|
|
|
if not is_pos and not is_kitchen:
|
|
if not user.has_group('point_of_sale.group_pos_manager'):
|
|
kitchen_root = self.env.ref('pos_enterprise.menu_point_kitchen_display_root', raise_if_not_found=False)
|
|
if kitchen_root:
|
|
kitchen_menus = self.env['ir.ui.menu'].sudo().search([('parent_path', 'like', kitchen_root.parent_path + '%')])
|
|
kitchen_menu_ids = set(kitchen_menus.ids)
|
|
kitchen_menu_ids.add(kitchen_root.id)
|
|
return res.filtered(lambda menu: menu.id not in kitchen_menu_ids)
|
|
return res
|
|
|
|
allowed_ids = set()
|
|
|
|
if is_pos:
|
|
pos_root = self.env.ref('point_of_sale.menu_point_root', raise_if_not_found=False)
|
|
if pos_root:
|
|
pos_menus = self.env['ir.ui.menu'].sudo().search([('parent_path', 'like', pos_root.parent_path + '%')])
|
|
pos_menu_ids = set(pos_menus.ids)
|
|
pos_menu_ids.add(pos_root.id)
|
|
|
|
# Submenus to hide: Orders, Products, Reporting, Configuration
|
|
exclude_xml_ids = [
|
|
'point_of_sale.menu_point_of_sale',
|
|
'point_of_sale.pos_config_menu_catalog',
|
|
'point_of_sale.menu_point_rep',
|
|
'point_of_sale.menu_point_config_product'
|
|
]
|
|
exclude_ids = set()
|
|
for xml_id in exclude_xml_ids:
|
|
menu = self.env.ref(xml_id, raise_if_not_found=False)
|
|
if menu:
|
|
descendants = self.env['ir.ui.menu'].sudo().search([('parent_path', 'like', menu.parent_path + '%')])
|
|
exclude_ids.update(descendants.ids)
|
|
exclude_ids.add(menu.id)
|
|
|
|
allowed_ids.update(pos_menu_ids - exclude_ids)
|
|
|
|
if is_kitchen:
|
|
kitchen_root = self.env.ref('pos_enterprise.menu_point_kitchen_display_root', raise_if_not_found=False)
|
|
if kitchen_root:
|
|
kitchen_menus = self.env['ir.ui.menu'].sudo().search([('parent_path', 'like', kitchen_root.parent_path + '%')])
|
|
allowed_ids.update(kitchen_menus.ids)
|
|
allowed_ids.add(kitchen_root.id)
|
|
|
|
return res.filtered(lambda menu: menu.id in allowed_ids)
|