gpt4 book ai didi

xml - Odoo:如何继承菜单项(使菜单项不可见)

转载 作者:行者123 更新时间:2023-12-05 09:21:30 25 4
gpt4 key购买 nike

我需要删除(或隐藏)一个菜单项。我想这应该通过继承和 xpath 来完成。

但我不确定应该使用哪个名称、模型和 inherit_id。我在哪里可以找到这些的正确值?

我也不知道如何为此正确使用 xpath。据我所知,只有页面、组和字段的表达式?( http://www.odoo.yenthevg.com/xpath-expressions-in-odoo-8/ )

必须删除的菜单是 Product Variants: enter image description here

在 addons/product/product_view.xml 中我发现了一些可能与它有关的东西。

第 1 行:

<menuitem id="base.menu_product" name="Product Variants" parent="base.menu_base_partner" sequence="9"/>

第 444-446 行:

<menuitem action="variants_action"
id="menu_variants_action"
parent="product.prod_config_main" sequence="10" />

我试图让菜单项在我自己的 views.xml 中不可见的方式:

    <record model="ir.ui.view" id="menuproductvariants_inherit">
<field name="name">name">product.prod_config_main</field>
<field name="model">base.menu_product</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml">
<xpath expr="//menuitem[@string='Product Variants']" position='replace'>
<menuitem name=""/>
</xpath>
</field>
</record>

它给出的错误:

ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Element '<xpath expr="//menuitem[@string='Product Variants']">' cannot be located in parent view

Error context:
View `name">product.prod_config_main`
[view_id: 971, xml_id: n/a, model: base.menu_product, parent_id: 257]" while parsing /root/git/odoo/modulesdewieuw/dewieuw/views.xml:59, near
<record model="ir.ui.view" id="menuproductvariants_inherit">
<field name="name">name"&gt;product.prod_config_main</field>
<field name="model">base.menu_product</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//menuitem[@string='Product Variants']" position="replace">
<menuitem name=""/>
</xpath>
</field>
</record>

编辑:根据创建新组的提示,我试了一下。我创建了一个组“verborgenmenus”并向其中添加了一个用户。

在我的 xml 中,我只是把它放在某处:

<menuitem id="base.menu_product" name="Product Variants" parent="base.menu_base_partner" sequence="9" groups="verborgenmenus"/>

它给我以下错误:

    raise ValueError('External ID not found in the system: %s' % (xmlid))
ParseError: "External ID not found in the system: dewieuw.verborgenmenus" while parsing /root/git/odoo/modulesdewieuw/dewieuw/views.xml:34, near
<menuitem id="base.menu_product" name="Product Variants" parent="base.menu_base_partner" sequence="9" groups="verborgenmenus"/>

我的代码有什么问题?

编辑:我通过从可用性/技术特性组中删除用户来实现我想要的效果。

最佳答案

实际上,给定一个菜单项,这是使用“隐藏”组隐藏菜单项的正确方法

    <record model="res.groups" id="group_invisible">
<field name="name">Hidden items</field>
</record>


<record id="module_id.menu_id" model="ir.ui.menu">
<field name="groups_id" eval="[(6, False, [ref('module_id.group_invisible')])]"/>
</record>

这对我来说很好用。当然,您也可以使用它来重新定义其其他属性(父级、名称等...)

关于xml - Odoo:如何继承菜单项(使菜单项不可见),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31964351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com