Skip to Content
Menu
This question has been flagged

Hi I'm trying to do that, hide the create and edit button from product_id in move lines in stock.picking

On the invoices for example I do it like this

<record id="invoice_view_inherit_duvan1" model="ir.ui.view">
<field name="name">my.invoice.custom</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
</field>
</record>

But when I try on stock picking like this 

<record id="picking_view_inherit_duvan1" model="ir.ui.view">
<field name="name">my.picking.custom2</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field[@name='move_lines']/tree/field[@name='product_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
</field>
</record>

It appears the following error 

Element '<xpath expr="//form/sheet/notebook/page/field[@name='move_lines']/tree/field[@name='product_id']">' cannot be located in parent view

If someone know what I'm doing wrong I would really appreciate it 

Thank you

Avatar
Discard
Best Answer

Hi Duvan,

The stock picking view doesn't actually define the tree view used by the move_lines field. Views can either define the views they use,  or just use the mode parameter, which will use either the context or default to render the view. 

If you take a look at the view definition, you'll see it only defines the kanban view, but has mode="tree,kanban". The context then says to use the stock.view_move_picking_tree view. Instead of targeting the picking view, you need to target the default stock.move tree view stock.view_move_picking_tree view.

Also, there's no need to be so specific with the xpaths,  //field[@name='move_lines']/tree/field[@name='product_id'] will work just fine, and will be more likely to migrate correctly, or at least show a better intention when migrating.

Cheers,
Jake Robinson

Avatar
Discard
Author

Hi, thank you for your answer, I'm trying like this

<record id="picking_view_inherit_duvan1" model="ir.ui.view">

<field name="name">my.picking.custom2</field>

<field name="model">stock.picking</field>

<field name="inherit_id" ref="stock.view_move_picking_tree"/>

<field name="arch" type="xml">

<xpath expr="//field[@name='move_lines']/tree/field[@name='product_id']" position="attributes">

<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>

</xpath>

<!--<xpath expr="//field[@name='partner_id']" position="attributes">

<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>

</xpath>-->

</field>

</record>

But it tells me the same error like this

Element '<xpath expr="//field[@name='move_lines']/tree/field[@name='product_id']">' cannot be located in parent view

You know what I'm doing wrong here? I change the ref to stock.view_move_picking_tree but still don't work. Thank you in advance

Sorry, I made that confusing. The long xpath was just a side note.

When modifying the stock move tree view, there won't be the field move_ids. All you will need is //field[@name='product_id']

Author

Thank you! It work like that I also had to change the model from stock.picking to stock.move!

Related Posts Replies Views Activity
1
Jun 23
1821
1
Jun 22
3127
2
Mar 22
7908
3
Aug 20
3761
3
Feb 20
2646