Development Book V17: View Inheritance

In Odoo, view inheritance is a powerful concept that allows you to extend or modify existing views without directly modifying their source code. This is beneficial for customization and maintaining code integrity. View inheritance is commonly used in Odoo modules to make changes to existing views defined in other modules.


                            <record model="ir.ui.view" id="sale_margin_sale_order_line">
                               <field name="name">sale.order.view.form.inherit.hospital.management</field>
                               <field name="model">sale.order</field>
                               <field name="inherit_id" ref="sale.view_order_form"/>
                               <field name="arch" type="xml">
                                   <xpath expr="//field[@name='payment_term_id']" position="after">
                                       <field name="margin"/>
                                   </xpath>
                               </field>
                            </record>
                            

The above code is a customization for the sale order form view. It introduces a new field named "margin" within the form for the "sale.order" model. This customization, named "sale.order.view.form.inherit.hospital.management," inherits from the existing view with the ID "sale.view_order_form." The new "margin" field is inserted after the "payment_term_id" field using an XPath expression in the XML architecture.

Moreover, multiple XPath values can be specified in Odoo XML view customizations, offering a diverse range of expression options.Some examples are


                                expr="//field[@name='user_id']"
                                expr="//sheet/div[last()]"
                                expr="/kanban"
                                expr="."
                                expr="//filter[@name='activities_overdue']
                                expr="//header"
                                expr="//button[@name='action_open_product_lot']"
                                

Furthermore, it is possible to specify different positions for XPath expressions in Odoo XML view customization. This includes:

  • position="after": This positions the specified field after the parent view mentioned in the "expr."
  • position="before": By using this attribute, the field is displayed before the parent view indicated in the "expr."
  • position="inside": With this setting, the field is presented inside the parent view identified in the "expr."
  • position="attributes": This option allows developers to modify the attributes of the indicated field.
  • position="replace": Using this attribute, the parent view field is replaced with the newly created field.
whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message