根据系统参数odoo 15显示菜单项
show menu item based on system parameter odoo 15
如何show/hide基于系统参数的菜单项?
我有这个代码来创建菜单项,它工作正常,但我需要隐藏它取决于系统参数。
<!-- this is for test, remove this after testing -->
<record id="check_qty_and_move_from_internal_customer_to_customer" model="ir.actions.server">
<field name="name">Cron Run Directly 2</field>
<field name="model_id" ref="model_kiotviet_cron"/>
<field name="binding_model_id" ref="onnet_kiotviet.model_kiotviet_cron"/>
<field name="state">code</field>
<!-- function called -->
<field name="code">model.check_qty_and_move_from_internal_customer_to_customer()</field>
</record>
<!-- this is for test, remove this after testing -->
<menuitem id="check_qty_and_move_from_internal_customer_to_customer" name="Cron Run Directly 2" parent="kiotviet_menu_root"
action="check_qty_and_move_from_internal_customer_to_customer" sequence="6"/>
有人知道怎么做吗?谢谢
我找到了答案,就在这里:
from odoo import models, api, 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)
# get system parameter
if not self.env['ir.config_parameter'].sudo().get_param('your_module.your_config_name'):
# get menu item id
menu_item_id = self.env.ref('your_module.menu_item_id').id
# remove it from menus
menus.dis
卡片(menu_item_id)
return 菜单
如何show/hide基于系统参数的菜单项?
我有这个代码来创建菜单项,它工作正常,但我需要隐藏它取决于系统参数。
<!-- this is for test, remove this after testing -->
<record id="check_qty_and_move_from_internal_customer_to_customer" model="ir.actions.server">
<field name="name">Cron Run Directly 2</field>
<field name="model_id" ref="model_kiotviet_cron"/>
<field name="binding_model_id" ref="onnet_kiotviet.model_kiotviet_cron"/>
<field name="state">code</field>
<!-- function called -->
<field name="code">model.check_qty_and_move_from_internal_customer_to_customer()</field>
</record>
<!-- this is for test, remove this after testing -->
<menuitem id="check_qty_and_move_from_internal_customer_to_customer" name="Cron Run Directly 2" parent="kiotviet_menu_root"
action="check_qty_and_move_from_internal_customer_to_customer" sequence="6"/>
有人知道怎么做吗?谢谢
我找到了答案,就在这里:
from odoo import models, api, 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)
# get system parameter
if not self.env['ir.config_parameter'].sudo().get_param('your_module.your_config_name'):
# get menu item id
menu_item_id = self.env.ref('your_module.menu_item_id').id
# remove it from menus
menus.dis
卡片(menu_item_id) return 菜单