Odoo: How to inherit menu items (make menu items i

2020-06-06 06:57发布

问题:

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.

回答1:

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


回答2:

You can't make a menuitem invisible in Odoo as if it were a field. You must remove it with the delete tag:

<delete id="your_module.tour_xml_id" model="ir.ui.menu"/>

A way to make it invisible without removing it is to add the attribute groups to the menuitem, and put there a group whose components are only the users who can see the menuitem. If you don't want any user to see it, then create a empty group and assign it that attribute:

<menuitem id="your_module.tour_xml_id" groups="empty_group"/>


回答3:

Actually, given a menuitem, this is the correct way to hide a menuitem by using an "hiding" group

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

This works just fine for me. Of course you can use it also for redefine others of its properties (parent, name, etc...)



回答4:

You can delete it like this:

<delete model="ir.ui.menu" id="module_name.menuitem_id"/>

But it's not recommendable, because maybe some other module is trying to access it. Instead of that you can add it to the admin group to make it invisible for the rest of users:

<menuitem id="module_name.menuitem_id" parent="module_name.parent_id" sequence="1" groups="base.group_no_one"/>

Update:

In your case the id of the menuitem should be id="product.menu_products"



回答5:

<record id="hide" model="res.groups">
    <field name="name">Hide</field>
    <field name="comment">Hide.</field>
</record>

<menuitem id="product.menu_products" name="Product Variants" parent="base.menu_product" sequence="10" groups="hide"/>

You also need to remove "Usability/Technical Features" from this menu..

For that Goto : Settings -> User Interface -> Menu Items. Search : product variants open form view : remove "Usability/Technical Features" from group grid.



回答6:

The answer of BBBagdiya its right, I only have to add the name property, because its has a not-null constraint.

The code is:

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


回答7:

You can Hide a menu by

<record model="ir.ui.menu" id="module_name.menu_id">
    <field name="action" eval="False"/>
</record>