41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class QuickMenuController(http.Controller):
|
|
@http.route('/web/quick_menu/get_menus', type='json', auth='user')
|
|
def get_quick_menus(self):
|
|
"""获取当前用户的快捷菜单配置"""
|
|
QuickMenuConfig = request.env['quick.menu.config']
|
|
menus = QuickMenuConfig.search([
|
|
('user_id', '=', request.env.user.id),
|
|
('active', '=', True)
|
|
], order='sequence')
|
|
|
|
result = []
|
|
for menu in menus:
|
|
# 检查菜单是否存在且用户有权限访问
|
|
if menu.menu_id and menu.menu_id.action and request.env.user.has_group('base.group_user'):
|
|
action = menu.menu_id.action.sudo()
|
|
action_type = action._name.split('.')[0]
|
|
|
|
# 获取action的完整信息
|
|
action_data = action.read()[0]
|
|
if action_type == 'ir':
|
|
action_data.update({
|
|
'type': 'ir.actions.act_window',
|
|
'target': 'current',
|
|
})
|
|
|
|
result.append({
|
|
'id': menu.id,
|
|
'name': menu.name or menu.menu_id.name,
|
|
'icon': menu.icon,
|
|
'color': menu.color or '#2ECC71', # 如果颜色为空,使用默认颜色
|
|
'action': action_data,
|
|
'sequence': menu.sequence,
|
|
'menu_id': menu.menu_id.id,
|
|
'show_title': menu.show_title,
|
|
})
|
|
|
|
return result |