本文介绍了Odoo:如何继承菜单项(使菜单项不可见)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



我也不知道如何正确使用xpath。
据我所知,页面,组和字段只有表达式?



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



第1行:

 < menuitem id =base.menu_productname =产品变体parent =base.menu_base_partnersequence =9/> 

第444-446行:

 < menuitem action =variants_action
id =menu_variants_action
parent =product.prod_config_mainsequence =10/>

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

 < record model =ir.ui.viewid =menuproductvariants_inherit> 
< field name =name> name> product.prod_config_main< / field>
< field name =model> base.menu_product< / field>
< field name =inherit_idref =product.product_template_only_form_view/>
< field name =archtype =xml>
< xpath expr =// menuitem [@ string ='Product Variants']position ='replace'>
< menuitem name =/>
< / xpath>
< / field>
< / record>

它给出的错误:

  ParseError:ValidateError 
Field(s)`arch`对一个约束失败:无效的视图定义

错误详情:
元素'< xpath expr =// menuitem [@ string ='Product Variants']>'无法在父视图中找到

错误上下文:
查看`name> product.prod_config_main`
[view_id:971,xml_id:n / a,model:base.menu_product,parent_id:257]在解析/时root / git / odoo / modulesdewieuw / dewieuw / views.xml:59,接近
< record model =ir.ui.viewid =menuproductvariants_inherit>
< field name =name> name& gt; product.prod_config_main< / field>
< field name =model> base.menu_product< / field>
< field name =inherit_idref =product.product_template_only_form_view/>
< field name =archtype =xml>
< xpath expr =/ / menuitem [@ string ='Product Variants']position =replace>
< menuitem name =/>
< / xpath>
< / field> ;
< / record>

编辑:之后关于创建新组的提示我试过了。
我创建了一个组verborgenmenus并添加了一个用户。



在我的xml中我只是把它放在某个地方:

 < menuitem id =base.menu_productname =Product Variantsparent =base。 menu_base_partnersequence =9groups =verborgenmenus/> 

它给了我以下错误:

 提高ValueError('在系统中找不到外部ID:%s'%(xmlid))
ParseError:解析/root/git/odoo/modulesdewieuw/dewieuw/views.xml:34时,系统中找不到外部ID:dewieuw.verborgenmenus,接近
< menuitem id =base.menu_productname =Product Variantsparent =base.menu_base_partnersequence =9groups =verborgenmenus/>

我的代码有什么问题?



编辑:我只是将用户从可用性/技术功能组中删除,我就得到了它。

解决方案
 < record id =make_invisiblemodel =res.groups> 
< field name =name> Invisible< / field>
< / record>
< record model =ir.ui.menuid =base.menu_product>
< field name =groups_ideval =[(6,0,[ref('make_invisible')])] />
< / record>


I need to remove (or make invisible) a menu item.I guess this should be done with an inherit and xpath.

But I'm not sure which name, model and inherit_id I should use. Where can I find the correct values for these?

I also don't know how to use xpath correctly for this.As far as I know, there are only expressions for pages, groups and fields?(http://www.odoo.yenthevg.com/xpath-expressions-in-odoo-8/)

The menu that has to be removed is Product Variants:

In addons/product/product_view.xml I found something that might have to do with it.

Line 1:

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

line 444-446:

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

The way I tried to make the menu item invisible in my own 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>

The error it gives:

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>

Edit: After the tips on making a new group I tried it.I've created a group "verborgenmenus" and added a user to it.

In my xml I just put this, somewhere:

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

It gives me the following error:

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

What is wrong in my code?

Edit: I got it how I wanted by just removing the users from the group Usability/Technical Features.

解决方案
<record id="make_invisible" model="res.groups">
    <field name="name">Invisible</field>
</record>
<record model="ir.ui.menu" id="base.menu_product">
    <field name="groups_id" eval="[(6,0,[ref('make_invisible')])]"/>
</record>

这篇关于Odoo:如何继承菜单项(使菜单项不可见)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 07:12