Odoo 17 View Inheritance for Backend Customization

November 24, 2025 by
Odoo 17 View Inheritance for Backend Customization
Fazri Muhammad Yazid

Odoo 17 allows developers to customize existing views without altering the original source code. This is done through view inheritance, where we create extension views that apply changes on top of the base (original) views. In this tutorial, we’ll explain Odoo’s view inheritance mechanism and walk through a full example of inheriting and modifying the product form view using XML. We’ll cover how to find the correct view to extend, how to use xpath and position in the XML, and best practices to ensure your customizations are upgrade-safe and conflict-free.


Understanding Odoo’s View Inheritance Mechanism

In Odoo, views (forms, tree lists, kanbans, etc.) are stored as records in the database. Instead of directly modifying these base view records, Odoo uses view inheritance to apply your changes. A child (extension) view references a parent (base) view via the inherit_id field and includes instructions (usually with xpath) to add, modify, or remove elements in the parent view. This way, the original view remains intact, and multiple modules can extend the same view safely.

When Odoo renders a view, it starts with the base view and then applies all extension views that inherit it (based on module load order and view priority) to produce the final combined interface. This mechanism is powerful: extension views can add new fields or buttons, change attributes, or even remove elements from the original view, all without editing the original XML file.

The Role of xpath and position in XML Inheritance

Within an inherited view’s XML, we use xpath expressions and position attributes to locate parts of the parent view and specify how to modify them.

xpath: The xpath tag’s expr attribute is an XPath expression that selects an element (node) in the parent view’s XML structureodoo.com. For example, expr="//field[@name='categ_id']" would find the <field name="categ_id"/> element wherever it appears. The expression should be specific enough to find one element; if it finds none or multiple, Odoo will throw a view error. You can use any valid XPath syntax, such as filtering by attributes or position. Common approaches include selecting by field name, page name, or other unique attributes. (Tip: Odoo also allows a shorthand where you can directly select elements by their tag and attributes without an explicit <xpath> wrapper we’ll see an example later.)

Position, The position attribute tells Odoo what to do with the matched element. Odoo supports several positions for inheritance operations:

  • after – Insert your content after the matched element (as a sibling. Use this to add new fields or buttons below or after an existing field/button.
  • before – Insert your content before the matched element (as a sibling)
  • inside – Insert your content inside the matched element (as its child, typically at the end of it).​ This is commonly used to add new elements inside a group or notebook page, or to add a new page inside a notebook.
  • replace – Completely replace the matched element with your conten. Use with caution: this removes the original element from the view and substitutes your version.
  • attributes – Modify the attributes of the matched element. This is used in combination with <attribute> tags inside the xpath to set or alter attributes (for example, making a field invisible or readonly).

For example, consider this snippet from the Odoo 17 documentation demonstrating view inheritance:

<record id="inherited_model_view_form" model="ir.ui.view">
    <field name="model">inherited.model</field>
    <field name="inherit_id" ref="inherited.inherited_model_view_form"/>
    <field name="arch" type="xml">
        <!-- find field 'description' and add 'new_field' after it -->
        <xpath expr="//field[@name='description']" position="after">
            <field name="new_field"/>
        </xpath>
    </field>
</record>

Here, the xpath finds the <field name="description"/> in the parent view, and position="after" inserts a new field right after that element​. As a result, new_field will appear immediately after description in the form view, without having to redefine the entire form.

Shorthand targeting: Instead of using an explicit <xpath> tag, Odoo allows a shortcut where you directly specify the element to match. For instance, the above could also be written as:

<field name="description" position="after">
    <field name="new_field"/>
</field>

Odoo interprets <field name="description" position="after"> as “find the field with name 'description' and insert the following content after it". This shorthand works for simple cases, but using full <xpath> gives you more flexibility (e.g., complex XPath conditions).


Example: Inheriting and Modifying the Product Form View

Adding a new field to the Product form using view inheritance. We’ll add a custom field called “Custom Field” to the product form (just as an example; it could represent any custom info you need to show on the product form).

Step 1: Extend the Model (Add a New Field)

from odoo import models, fields

class ProductTemplate(models.Model):
    _inherit = 'product.template'
    x_custom_field = fields.Char(string="Custom Field")

Step 2: Create the Inherited View XML

Now, in our module’s XML (usually in a file under views/ folder, e.g., views/product_form_inherit.xml), we write a <record> to inherit and modify the product form view:

<odoo>
    <record id="product_template_form_inherit_custom" model="ir.ui.view">
        <field name="name">product.template.form.inherit.custom</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_form_view"/>
        <field name="arch" type="xml">
            <!-- Insert our custom field after the product Category field -->
            <xpath expr="//field[@name='categ_id']" position="after">
                <field name="x_custom_field" placeholder="Custom Info"/>
            </xpath>
        </field>
    </record>
</odoo>

Step 3: Update Manifest

After adding the XML, include this XML file in your module’s __manifest__.py under the 'data': [...] list, so it gets loaded. Also ensure 'product' is listed in depends. For example, in the manifest:

'depends': ['product'],
'data': [
    'views/product_form_inherit.xml',
],

Now Upgrade your module (via Apps menu or command line). When you open a Product form, you should see the new Custom Field appearing after the Category field.


Odoo 17 View Inheritance XML Syntax Summary

XML Element/ Attribute

Purpose/Description

Example of Usage

inherit_id

References the XML ID of the existing view to inherit/extend. Placing this in a view definition tells Odoo which base view to modify.

<field name="inherit_id" ref="base.view_partner_form" />

model

Specifies the model that the view applies to. This should usually match the model of the inherited view, ensuring the extension attaches to the correct object.

<field name="model">res.partner </field>

arch

The field that contains the view architecture (XML structure). In an inherited view, the <field name="arch" type="xml"> encloses the modifications (generally one or more xpath entries) that will be merged into the parent view.

<field name="arch" type="xml"> ... view content ... </field>

xpath

An element used to locate a node in the parent view and insert or alter content. The xpath uses an expression (expr) to find the target element in the parent, and its inner XML defines the changes (new fields, containers, etc.) to apply.

<xpath expr="//field[@name='email']" position="after"> <field name="x_custom_field"/> </xpath>

expr (attribute on xpath)

The XPath expression that selects the target element(s) in the parent view. It must match exactly one node (or an error is raised). Developers use expr to pinpoint where in the XML view to apply their changes (e.g. by matching a field name or XML ID).

<xpath expr="//field[@name='email']" ...> ... </xpath>

position (attribute on xpath)

Specifies how to insert or apply the changes relative to the matched element. Common values include after (insert content after the target node), before (insert before it), inside (insert inside it as a child), replace (replace the target node entirely), and attributes (modify the target node’s attributes)

<xpath expr="//field[@name='phone']" position="replace"> <field name="x_alternate_phone"/> </xpath>

attribute

Used within an xpath (with position="attributes") to set or change an attribute value on the target element. Each <attribute> tag names an attribute of the matched element and gives it a new value.

<xpath expr="//field[@name='phone']" position="attributes"> <attribute name="string">Contact Phone</attribute> </xpath>

field (element in view arch)

Represents a model field to display in the view. In view inheritance, you often use <field> tags inside your xpath to add new fields to a form or tree. The name attribute specifies the technical field name, and you can optionally set attributes like string (label).

<xpath expr="//field[@name='email']" position="after"> <field name="x_custom_field" string="Custom Field"/> </xpath>



Odoo 17 View Inheritance for Backend Customization
Fazri Muhammad Yazid November 24, 2025
Share this post
Archive