66 lines
2.5 KiB
Python
66 lines
2.5 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
|
|
|
|
@http.route("/web/quick_menu/get_visibility", type="json", auth="user")
|
|
def get_quick_menu_visibility(self):
|
|
"""返回当前用户的快捷菜单显示状态"""
|
|
user = request.env.user.sudo()
|
|
return {"is_visible": bool(user.quick_menu_is_visible)}
|
|
|
|
@http.route("/web/quick_menu/set_visibility", type="json", auth="user")
|
|
def set_quick_menu_visibility(self, is_visible):
|
|
"""更新当前用户的快捷菜单显示状态"""
|
|
user = request.env.user.sudo()
|
|
normalized_value = is_visible
|
|
if not isinstance(is_visible, bool):
|
|
normalized_value = str(is_visible).lower() in ("1", "true", "t", "yes", "y")
|
|
user.write({"quick_menu_is_visible": normalized_value})
|
|
return {"is_visible": normalized_value}
|