Odoo 18: Extending Models and Views Without Modifying Core

Point-of-sale equipment in a retail store
Photo by SumUp on Unsplash. Visual editorial reference, not a verified screenshot of the software discussed. · View original image

Add a field to the contact form as an interface task: look for an XML item and insert another. At Odoo this modification goes through several layers. The field should exist in the model. The addon should declare its dependencies. The inherited view should place the right node. The operation should respect the user’s permission and an update of the module should be able to apply the extension without altering the product code.

That’s why the rule “don’t edit the core” is necessary but insufficient. A maintenance customization depends on contracts between modules, models, views, security and assets. That analysis is limited to Odoo 18.0 and does not mean that the same XML selectors and internal APIs are equal to 17, 19 or a future version.

Technical diagram accompanying Odoo 18: Extending Models and Views Without Modifying Core
Original editorial chart. Module customization are separated from the original core files.

What it means to really inherit at Odoo

Odoo has several mechanisms that share the word * inheritance * but have different functions:

MechanismWhat modifiesWhen appropriate
_inherit = 'res.partner' without _nameExpand the existing modelAdd fields or conduct to contacts
_name with _inheritCreate a new model based on anotherA different entity with inherited conduct
_inherits = {'otro.modelo': 'campo_id'}Delegation fields through relationsComposition among models with documented limitations
inherit_id at ir.ui.viewApply instructions to a base or inherited viewExpand forms, lists and other views

They aren’t interchangeable alternatives. _inherits holds delegation and documentación del ORM de Odoo 18 warns that methods are not inherited as fields and that chained delegated inheritance has limitations. To add a property to res.partner, the extension * in place * using _inherit is usually the direct track.

Original conceptual illustration accompanying Odoo 18: Extending Models and Views Without Modifying Core; not a screenshot.
Original conceptual illustration of this article's topic; not a screenshot or measured result.

A minimum addon and an explicit dependence

Let’s have a deliberately small customization: add an optional logistics note to a contact. It does not introduce an independent model or require information about confidential information. The addon directory can be arranged as follows:

partner_operations/
├── __init__.py
├── __manifest__.py
├── models/
│   ├── __init__.py
│   └── res_partner.py
└── views/
    └── res_partner_views.xml

The manifesto states what module you need to work and what XML loads:

# partner_operations/__manifest__.py
{
    'name': 'Partner Operations Notes',
    'version': '18.0.1.0.0',
    'depends': ['base'],
    'data': [
        'views/res_partner_views.xml',
    ],
    'installable': True,
    'application': False,
}

In this example the base dependence is sufficient as res.partner and its base form are extended. A gift that inherits a view of sale, stock or point_of_sale should include the module that owns that view among its dependencies. The Loading Order does not solve with an XML priority and depends on the module graph stated in depends. See ZXQHOLDER6 ZXQ.

The __init__.py matter the model package and its file:

# partner_operations/__init__.py
from . import models

# partner_operations/models/__init__.py
from . import res_partner

The field exists before to be referred to at the glance:

# partner_operations/models/res_partner.py
from odoo import fields, models


class ResPartner(models.Model):
    _inherit = 'res.partner'

    logistics_note = fields.Char(string='Nota logística')

That adds an attribute to the existing model. It should not be confused with creating a new table using _name. Nor does it mean that all users can read or modify the field: their permits continue to depend on the model’s security mechanisms and, if established, the groups allowed for the field.

Inheritance of views: localizing and applying changes

The original contact form view is stated with the base.view_partner_form identifier in the Odoo 18 code. The following example introduces logistics_note after the first email node found by the XPath locator:

<!-- partner_operations/views/res_partner_views.xml -->
<odoo>
  <record id="view_partner_form_operations_note" model="ir.ui.view">
    <field name="name">res.partner.form.operations.note</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
      <xpath expr="//field[@name='email']" position="after">
        <field name="logistics_note"/>
      </xpath>
    </field>
  </record>
</odoo>

What was verified: the official repository odoo/odoo, branch 18.0, contains the register view_partner_form and a email field at that glance. What was not verified: the installation of this addon, the result of a combination of a light and its interaction with other modules that inherited the same form. In an instance with additional addins, the final result depends on the inheritance sequence and modifications already applied.

inherit_id does not copy the whole view. The system starts from a determined father’s view and applying the specifications of an extended view, also with resort and priorities have an impact on order between extensions. The View Records, Odoo 18 manual explain that resolution.

A stable XPath isn’t necessarily the longest

A global expression such as //field[@name='email'] can be sufficient if there’s a single coincidence in the intended combination architecture but it’s fragile if another extension introduces a field with the same name. The documentation indicates that the legacy XPath locator applying the first coincidence. More accuracy is useful when responding to a proven structure, but not when adding positive routes such as group[3]/group[2] that change with small modifications of IU.

The practical strategy is to inspect the combined view of the target base, select a semantic anchor that actually exists and record why it was chosen. The above example is a pedagogical starting point, and not a promise of universal compatibility.

after, attributes, replace and move

The most common changes have no same impact:

  • before, after and inside insert contents with respect to the located node.
  • attributes modifies attributes without replacing the whole item.
  • replace replaces the located node and can remove added behavior by other extensions.
  • move allows you to relocate elements with an inheritance syntax documented at Odoo 18.

For example, changing only the visible label of a field can be expressed with attributes:

<xpath expr="//field[@name='email']" position="attributes">
  <attribute name="string">Correo principal</attribute>
</xpath>

That modifies the look of the view and does not renomerate the ORM field and ** does not set permits *. A required, invisible or readonly in XML can condition the conduct of that interface but should not become the only guarantee of a business or security rule. If the restriction matters outside the form, it should also be designed in the layer that processes operations.

Replacing a large node with position="replace" can work today and block a later modification of Odoo or another addon. It should be reserved for cases where the change is structural and covered by update tests.

Security: ACL, registration rules and fields

A regular error is to add a invisible="1" field and to consider information protected. Hiding a monitoring isn’t monitoring data access. Odoo applying safety in several layers:

ACL (ir.model.access). Determining which groups can conduct production, reading, writing and disposal operations on a model. They are model permits and are awarded aditially according to user groups and do not filter individual rows.

Record rules (ir.rule). Reg what records a particular operation can use. The global and group-associated rules are combined with different semantics and an absent rule does not amount to an additional model permission. Your design should be tested with actual users of each role.

Field access. An ORM field can be restricted by groups. The system controls its exposure to operations and methatatate and does not simply preserve it visually.

Business methods. A public method that receives IDs and RPC arguments should not treat these data as reliable. sudo() can greatly alter the permissibility context and a flow using them has to justify why it raises privileges and strictly limits the affected registries and actions. The capítulo oficial de seguridad de Odoo 18 document these risks.

In the addon of the logistics note we do not create a new model and we do not have to declare a new ACL simply by adding a field to res.partner. The existing model policy remains relevant. If the business requires that the note be confidential, that already requires a group decision and login evidence, not just an attribute of vision.

Assets and Owl: another form of extension, another border

When customization requires JavaScript, CSS, Templates or Owl components, an inherited form will no longer be enough. At Odoo 18 the files are added to * bundles * using the assets key from the manifesto. The operations append, prepend, before, after, replace, remove and include have rules of order, for example, to target an undeclared asset with before. Check Assets, Odoo 18.

A model independent from the previous Section field would be to declare an existing JavaScript module within the backend bundle:

# Fragmento conceptual del diccionario __manifest__.py.
# Solo incluirlo cuando el archivo exista realmente.
{
    'assets': {
        'web.assets_backend': [
            'partner_operations/static/src/js/backend_extension.js',
        ],
    },
}

That file isn’t part of the minimum addon described above and should not be added to the manifesto until there really are. Nor does any change of IU require an Owl patch: a declarative vision inheritance usually has lower maintenance area if the requirement is to insert or reorder fields.

A Owl component, a performance patch and an XML viewing extension affect different layers. Before you write JavaScript, you have to identify if the target is ORM data, XML composition, client interaction or cross-sectional service. The cost of a patch isn’t just measured by its length: it also counts how much it depends on internal APIs that can change when you update the version.

Updates and tests: check combination viewing

A customization is considered to be maintenance when resisting a compatible update and allows to detect bugs before the user opens the form. The best strategy for this example is:

  1. To install the module at a test base, never production as a first attempt.
  2. To inspect the result view of res.partner and confirm that logistics_note appears where expected.
  3. Test field creation and writing from ORM with relevant roles.
  4. Upgrade the addon into a copy of the base and check if the XPath expressions continue to solve.
  5. To conduct regression tests of flows that other modules have added to the same form.

A separate ORM test can check that the field exists and stores the value:

# tests/test_partner_note.py — requiere package tests/__init__.py
from odoo.tests.common import TransactionCase


class TestPartnerOperations(TransactionCase):
    def test_logistics_note_is_stored(self):
        partner = self.env['res.partner'].create({
            'name': 'Contacto de pruebas',
            'logistics_note': 'Entregar en recepción',
        })
        self.assertEqual(partner.logistics_note, 'Entregar en recepción')

That does not prove that the XPath has been applied and that the groups have the right permission: these conditions require specific testing or visual monitoring with a test user. The snippet was not run here and, to load the test, appropriate imports should also be added to the tests package and to the __init__.py module.

Before updating you should backup and get to know the base recovery mechanism. Fold an addon or restore a Git review does not automatically reset the program and data changes that have been made by the module. Recovery and compatibility of migration are part of the operation plan, and they are not inherit_id’s.

A different border from the Astro Islands

Astro composes components and can choose what hydrates in the browser and Odoo resolves inherited views, persistent models, safety rules and bangles within an integrated system. They’re not the same mechanism. The principle of shared design is more abstract: extension should declare what contract modifies and what remains beyond its liability. A bad border on a blog can produce unnecessary JavaScript; a bad border on ERP can display data, break an update or change a business operation.

If you are interested in contrasting both decisions, the articles about arquitectura Astro and islas Svelte develop the web rendering side. The fundamental unit here remains the Odoo module and its relationship with other modules.

Conclusion

Wounding a view with XPath is just the visible part of a customization. What’s difficult is to preserve the contract between an actual ORM field, an addon with dependencies, a combination view that changes with other modules and a security system that cannot be delegated to visual attributes. At Odoo 18, a small, explicit and verifiable addon is often easier to hold than a massive replacement of the base view.

Odoo References 18.0: Module Manifests, ORM API — Inheritance and extension, View Records — Inheritance, Security, Assets and vista original de contactos de la rama 18.0.