Jirakit Paitoonnaramit
Jirakit Paitoonnaramit

Reputation: 167

How to use XPath in Odoo

I having some problem in Odoo

<record id="lunch_order_view_form" model="ir.ui.view">
<field name="name">lunch.order.form</field>
<field name="model">lunch.order</field>
<field name="arch" type="xml">
    <form string='Orders Form' class="o_lunch">
    <header>
        <button name="%(action_lunch_order_line_lucky)d" type="action" string="Feeling Lucky" class="oe_highlight"/>
         <!-- HERE THAT I WANT TO ADD  -->

And then I use

<record id="lunch_order_view_form" model="ir.ui.view">
    <xpath expr="/lunch/views/lunch_views/field[@name='arch']" position="after">
        <button name="%(action_lunch_order_line_favorite)d" type="action" string="Favorite Menu" />
        hello
    </xpath>
</record>

but it now works how to define it?

Upvotes: 1

Views: 1749

Answers (1)

Heroic
Heroic

Reputation: 980

If header is already define in your parent form view , you can inherit it as below:

<record id="lunch_order_view_form_inherit" model="ir.ui.view">
    <field name="name">lunch.order.form.inherit</field>
    <field name="model">lunch.order</field>
    <field name="inherit_id" ref="parent_form_module_name.lunch_order_view_form"/>
    <field name="arch" type="xml">
        <xpath expr="//header" position="inside">
            <button name="%(action_lunch_order_line_favorite)d" type="action" string="Favorite Menu" />
        </xpath>
    </field>
</record>

You can replace parent_form_module_name with actual module name where you have define parent form.

Upvotes: 2

Related Questions