显示基于系统参数odoo 15的菜单项



如何根据系统参数显示/隐藏菜单项?

我有这个代码来创建菜单项,它工作得很好,但我需要隐藏它,这取决于系统参数。

<!-- 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(返回菜单

相关内容

  • 没有找到相关文章

最新更新