根据系统参数显示菜单项 odoo 15

发布于 2025-01-16 16:49:08 字数 960 浏览 2 评论 0原文

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

我有这段代码来创建菜单项,它工作正常,但我需要根据系统参数隐藏它。

<!-- 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"/>

有谁知道该怎么做?谢谢。

How to show/hide menu item based on system parameter?

I've this code to create menu item, and it working fine, but i need to hide it depends on system parameter.

<!-- 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"/>

Does anyone know how to do that? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼疼热情 2025-01-23 16:49:08

我找到了答案,就是:

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

card(menu_item_id)
返回菜单

I've found the answer, here is it:

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

card(menu_item_id)
return menus

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文