How to Use Inherit position in odoo

Hello Odooers & odoo Developers!

Welcome to our Odoo technical blog! In this post, we’ll talk about inheritance positions and how they help customize Odoo without modifying the core code.

Odoo inheritance feature allows you to extend or modify existing models, views, and behaviors easily. This makes your system more flexible, easier to maintain, and upgrade-friendly.

In this blog, we’ll focus on inheritance positions in views, explaining how they work with simple examples.

  • What inheritance positions are and how they work.
  • Different types of inheritance positions in Odoo.
  • How to define and use inheritance positions in Odoo views.
  • Practical examples to demonstrate their usage.

Understanding View Inheritance in Odoo

In Odoo, view inheritance allows you to customize existing views (like forms, lists, and kanban views) without modifying the original files. This is useful because it keeps your customizations upgrade-safe and prevents conflicts with future updates.

Odoo uses the <xpath> tag to locate elements in a view and modify them. You can add, replace, or remove elements by specifying a position inside the <xpath> tag.

Inheritance Positions in Odoo

When using <xpath>, you need to specify a position that tells Odoo how to modify the existing view. Here are the most common positions:

1. Before:

  • Adds new content before the selected element.
  • Example: Adding a button before an existing field.

example.xml

.py

  <xpath expr="//field[@name='name']" position="before">
<button name="custom_action" type="object" string="Button"/>
  </xpath>

Explanation: This adds a button before the "name" field in the form.

2. after:

  • Adds new content after the selected element.
  • Example: Adding a field after an existing field.

example.xml

.py

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

Explanation: This inserts custom_field after the "name" field.

3. inside :

  • Adds new content inside the selected element. This is useful for modifying containers like <group>, <div>, or <notebook>.
  • Example: Adding a field inside a group.

example.xml

.py

<xpath expr="//group" position="inside">
    <field name="custom_field"/>
</xpath>

Explanation: This adds custom_field inside the <group> tag.

4. replace:

  • Replaces the selected element with new content.
  • Example: Replacing a field with another field.

Example.xml

.py

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

Explanation: This replaces the "name" field with "custom_name".

5. attributes :

  • Modifies only the attributes of an existing element, without changing its structure.
  • Example: Changing a field’s label.

example.xml

.py

<xpath expr="//field[@name='name']" position="attributes">
    <attribute name="string">Custom Name</attribute>
</xpath>

Explanation: This changes the "name" field’s label to "Custom Name".

Conclusion:

When customizing views in Odoo 18, it's important to use view inheritance instead of modifying the original code. Odoo provides five inheritance positions that allow you to modify existing views safely and efficiently:

  1. before – Adds content before the targeted element.
  2. after – Adds content after the targeted element.
  3. inside – Inserts content inside the targeted element.
  4. replace – Replaces the targeted element entirely.
  5. attributes – Modifies the attributes (like class, invisible, etc.) of the targeted element.

By using these positions correctly, you can customize Odoo views while keeping your changes upgrade-safe and easy to maintain.

If you want odoo technical training on any odoo version , please let us know by mail at [email protected]. Then next, our odoo expert will conduct online or offline Odoo training with you 


Devintellecs & team are odoo training providers in the USA and INDIA, so we will try our best to give the training either individal or any bulk employee company.


If you want to check your odoo technical or functional knowledge, then we have prepared the odoo EXam practice test for the odoo technical & functional people.



Odoo DEV March 6, 2025
Share this post
Archive
Sign in to leave a comment
Customizing Widget Percentpie in odoo