ai动态报表
This commit is contained in:
@@ -11,7 +11,6 @@ class IrUiMenu(models.Model):
|
||||
string='菜单名拼音',
|
||||
compute='_compute_name_pinyin',
|
||||
store=True,
|
||||
index=True,
|
||||
)
|
||||
|
||||
@api.depends('name')
|
||||
@@ -24,6 +23,23 @@ class IrUiMenu(models.Model):
|
||||
first_letters = ''.join([p[0] for p in pypinyin.pinyin(menu.name)]).lower()
|
||||
menu.name_pinyin = f"{full_pinyin} {first_letters}"
|
||||
|
||||
def load_menus(self, debug):
|
||||
"""重写 load_menus,把拼音拼到菜单名后面,让 Ctrl+K 能搜到"""
|
||||
menus = super().load_menus(debug)
|
||||
# menus 是 dict 结构 {id: {name, parent_id, children, ...}}
|
||||
# 遍历所有菜单,把拼音追加到 name 后面
|
||||
for menu_id, menu_data in menus.items():
|
||||
if not isinstance(menu_data, dict) or not menu_data.get('name'):
|
||||
continue
|
||||
name = menu_data['name']
|
||||
# 查数据库获取 name_pinyin
|
||||
if menu_id and isinstance(menu_id, int):
|
||||
menu_record = self.browse(menu_id).exists()
|
||||
if menu_record and menu_record.name_pinyin:
|
||||
# 格式: "通知公告 [tongzhigonggao tzgg]"
|
||||
menu_data['name'] = f"{name} [{menu_record.name_pinyin}]"
|
||||
return menus
|
||||
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
if args is None:
|
||||
args = []
|
||||
|
||||
Reference in New Issue
Block a user