How to define correct XPath location?
odoo, python, xml
Solution
The root elements in the `arch` field of an inherited view are locators which are supposed to identify an element in the parent view, on which an operation can then be performed according to the special `position` attribute.
A locator must have a `position` attribute and can be either:
- an `<xpath>` element with an `expr` attribute containing a valid XPath expression for locating a single element in the parent view;
- any valid view element from the parent view;
An inherited view can have multiple root elements, in order to perform several alteration to the parent view.
Your example is incorrect because you have nested several locators: your `xpath` elements are inside the `page` element. Notice that 3 elements have a `position` attribute in your inherited view: the `notebook` element and the 2 `xpath` elements. They all need to be at the top of the view architecture, for example:
<field name="arch" type="xml">
<notebook position="inside">
<!-- ... elements you want to add inside the parent notebook -->
</notebook>
<xpath expr="/form/notebook/page/group/field[@name='ssnid']"
position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
<xpath expr="/form/notebook/page/group/field[@name='sinid']"
position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
PS: if you're not familiar with XPath, you should look online for a quick reference or cheat sheet, such as this one.
Problem
I was set ssnid & sinid as invisible fields.but both are still shows in my view.seems issue with XPath location.! Anyone can help me to sort out ? ``` <?xml version="1.0"?> <openerp> <data> <!-- 1st part of the sim_view start --> <record model="ir.ui.view" id="madulsima_plucker_form"> <field name="name">madulsima.plucker.form</field> <field name="model">madulsima.plucker</field> <field name="inherit_id" ref="hr.view_employee_form" /> <field name="type">form</field> <field name="arch" type="xml"> <notebook position="inside"> <page string="Madulsima Plucker Fields"> <field name="reg_no" /> <field name="worker_name" /> <xpath expr="/form/notebook/page/group/field[@name='ssnid']" position="attributes"> <attribute name="invisible">True</attribute> </xpath> <xpath expr="/form/notebook/page/group/field[@name='sinid']" position="attributes"> <attribute name="invisible">True</attribute> </xpath> </page> </notebook> </field> </record> <record model="ir.actions.act_window" id="action_plucker_registration"> <field name="name">Plucker Registration</field> <field name="res_model">madulsima.plucker</field> <field name="view_type">form</field> <field name="view_mode">form</field> </record> <menuitem id="menu_madulsima_plucker" name="Madulsima/Checkroll" /> <menuitem id="menu_madulsima_plucker_registration" name="Plucker Registration" parent="menu_madulsima_plucker" action="action_plucker_registration" /> </data> </openerp> ``` i posted my whole code in view.xml