0

In Odoo 9, I'm trying to inherit the purchase order form view (file: addons/purchase/purchase_view.xml, record: <record id="purchase_order_form" model="ir.ui.view">). What I need to do is, just edit an attribute of one page tag. I tried to select the desired page by using xpath, but it's not working fine.

Parent View Structure

<notebook>
    <page string="Products">
        ......
        ......
        <notebook>
        <page string="Notes">
            <field name="name"/>
        </page><page string="Invoices and Incoming Shipments">
            <field name="invoice_lines"/>
            <field name="move_ids"/>
        </page>
        </notebook>
        ......
        ......
    </page>
    <page string="Deliveries &amp; Invoices">


    </page>
</notebook>

In my view file, I used the following code to select the <page string="Deliveries &amp; Invoices"> and this is not working as expected.

<record model="ir.ui.view" id="purchase_order_type_form_view_inherit">
    <field name="name">purchase.order.form.inherit</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="priority">10000</field>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page[2]" position="attributes">
            <attribute name="groups">custom_module.manager</attribute>
        </xpath>
    </field>
</record>

Thanks in advance.

Nikhil Mohan
  • 891
  • 6
  • 13
  • The problem could be in two similar structures, which are nested. What about `/notebook/page[2]`? Just remove the first slash. Or try `//page[@string="Deliveries & Invoices"]`. Your XPath selects every second `page` item, no matter of what level. – Honza Hejzl Apr 05 '16 at 13:39
  • @HonzaHejzl Thanks for you help. Actually I can't use `//page[@string="Deliveries & Invoices"]` because Odoo 9 not supporting to use string attribute selection. I will try the first option very soon and let you know then. – Nikhil Mohan Apr 05 '16 at 14:21
  • @NikhilMohan show full xml of view please. I mean with `inherit_id` and `model`. – Danila Ganchar Apr 06 '16 at 12:47
  • @DanilaGanchar I have updated my question by putting full xml of view file. – Nikhil Mohan Apr 06 '16 at 13:34
  • 1
    @HonzaHejzl, DanilaGanchar `expr="/form/sheet[1]/notebook[1]/page[2]"` is giving me what I was looking for. Anyway thanks for your help. And if you foresee any issues with my solution, please tell me. – Nikhil Mohan Apr 06 '16 at 13:47

1 Answers1

1
<record model="ir.ui.view" id="purchase_order_type_form_view_inherit">
        <field name="name">purchase.order.form.inherit</field>
        <field name="model">hr_employee</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="priority">10000</field>
        <field name="arch" type="xml">
            <xpath expr="//form/sheet/notebook/" position="after">
                <page>
                    <group>
                            <group colspan="4" col="4">

                                <label for="employment_ids" colspan="4" />
                                <field name="employment_ids" colspan="4" nolabel="1">
                                    <form string="Employee Employment">
                                        <field name="organization" />
                                        <field name="job_title" />
                                        <field name="entered_date" />
                                        <field name="resigned_date" />
                                        <field name="resigned_reason" />
                                        <field name="responsibility" />
                                        <field name="wage" />
                                    </form>
                                    <tree string="Employee Employment" editable="bottom">
                                        <field name="organization" />
                                        <field name="job_title" />
                                        <field name="entered_date" />
                                        <field name="resigned_date" />
                                        <field name="resigned_reason" />
                                        <field name="responsibility" />
                                        <field name="wage" />
                                    </tree>
                                </field>
                            </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>