Hello,
I am having trouble using XPath to do anything with views. I've read a lot on StackOverflow and Odoo's official documentation about XPath and view inheritance, but I don't understand how to use it because it never seems to work for me. i am using the inventory app. If I use the following in my view, it correctly makes the list_price field invisible
<odoo>
<data>
<record id="view_kit_product_form" model="ir.ui.view">
<field name="name">kit_product_form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<field name="list_price" position="attributes">
<attribute name="invisible">True</attribute>
</field>
</field>
</record>
</data>
</odoo>
but replacing
<field name="list_price" position="attributes">
<attribute name="invisible">True</attribute>
</field>
with
<xpath expr="/form/sheet/notebook/page/group/group/field[name='list_price']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
or
<xpath expr="//field[@name='list_price']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
or
<xpath expr="field[@name='list_price']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
will always cause an error which creates a server error and tells me this:
Element '<xpath expr="field[@name=list_price]">' cannot be located in parent view.
In fact, trying to do anything with XPath has given me this error, and I don't understand why.
Shouldn't
<xpath expr="field[@name='list_price']"/>
Do the same thing as
<field name="list_price"/>
?
Can anybody tell me what I'm doing wrong? Or if there are any better resources which explain how to use XPath with Odoo and view inheritance, I would really appreciate it if you could tell me about them! I've seen people say you can use XPath with a view to even hide pages in a notebook in a form, but trying to do that also gives me an error.
Any help would be greatly appreciated
Hi, try this <xpath expr="//page[@name='general_information']/field[@name='list_price']" position="attributes">
That gives the same error:
Element '<xpath expr="//page[@name='general_information']/field[@name='list_price']">' cannot be located in parent view
Shouldn't
<xpath expr="field[@name='list_price']"/>
Do the same thing as
<field name="list_price"/>
?
It shouldn't as you're telling the machine to search on the top level only. Instead, it should be:
<xpath expr="//field[@name='list_price']" position="attributes">
...
</xpath>
But my guess is that you just have missed leading '//' for the second time. I tried your code, it all works fine except for the one without leading '//'. You should probably try checking the spelling.
Thank you thompsonn! You are right, and that is a helpful explanation that it is only searching the top level if you leave out "//"
Posted it as an answer, please don't hesitate to mark it as accepted :) Thanks
Read this: https://goo.gl/fGNfBY