ODOO: Extending the Sale Module

A practical walkthrough of creating a custom Odoo module that extends the Sale Order model. Covers the full module structure including the manifest, model extension, and view inheritance to add a custom field to the sale order form.

One of the most common Odoo development tasks is extending the Sale module — adding custom fields to sales orders, modifying confirmation logic, or adjusting the form view layout. This post walks through the complete process from scratch.


What We Are Building

We will create a custom module called custom_sale_extension that:

  • Adds a custom text field (x_custom_field) to the sale.order model
  • Displays the field on the sale order form view
  • Demonstrates the full Extension Inheritance workflow

Module Directory Structure

md
custom_sale_extension/
├── __init__.py
├── __manifest__.py
├── models/
│   ├── __init__.py
│   └── sale_order.py
└── views/
    └── sale_order_views.xml

Every file here serves a specific purpose. The structure follows the standard Odoo module layout and must be placed inside your Odoo add-ons directory.


Step 1: The Manifest File

The __manifest__.py file is the entry point Odoo reads to understand your module.

python
{
    'name': 'Custom Sale Extension',
    'version': '17.0.1.0',
    'summary': 'Extends the Sale module with custom features',
    'description': 'This module adds a custom field to the Sale Order model.',
    'author': 'VarApps',
    'depends': ['sale'],
    'data': [
        'views/sale_order_views.xml',
    ],
    'installable': True,
    'application': False,
}

Key Points

  • version: 17.0 prefix indicates compatibility with Odoo 17
  • depends: ['sale'] means the Sale module must be installed first
  • data: lists all XML files to load during installation — the order matters
  • application: False means this is an extension, not a standalone app

Step 2: Root `__init__.py`

This file tells Python to treat the directory as a package and imports the models subpackage:

python
from . import models

Without this, Odoo will not load any of your Python code.


Step 3: Models `__init__.py`

python
from . import sale_order

This imports your sale_order.py file so its class is registered with Odoo's ORM when the module loads.


Step 4: Extending the Sale Order Model

The sale_order.py file uses Extension Inheritance to add a custom field to the existing sale.order model.

python
from odoo import models, fields

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    x_custom_field = fields.Char(string="Custom Field")

What Happens Here

  • _inherit = 'sale.order' tells Odoo to extend the existing sale.order model
  • No _name is defined — this means we are not creating a new model, just extending the existing one
  • x_custom_field is a new column that will be added to the sale_order database table
  • The x_ prefix is the Odoo convention for custom fields, preventing naming conflicts

You can also override the action_confirm method to add custom logic when a sale order is confirmed:

python
from odoo import models, fields

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    x_custom_field = fields.Char(string="Custom Field")
    x_confirmed_by = fields.Char(string="Confirmed By", readonly=True)

    def action_confirm(self):
        # Call original confirmation logic first
        result = super(SaleOrder, self).action_confirm()
        # Add custom logic after confirmation
        for order in self:
            order.x_confirmed_by = self.env.user.name
        return result


Step 5: Extending the Sale Order View

The sale_order_views.xml file extends the existing sale order form view to display the new field.

xml
<odoo>
    <record id="view_order_form_inherit_custom" model="ir.ui.view">
        <field name="name">sale.order.form.inherit.custom</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <sheet position="inside">
                <group>
                    <field name="x_custom_field"/>
                </group>
            </sheet>
        </field>
    </record>
</odoo>

XML Breakdown

AttributeValueDescription
idview_order_form_inherit_customUnique ID for this view record
modelir.ui.viewWe are creating a view record
namesale.order.form.inherit.customName of the inherited view
model (field)sale.orderThe model this view applies to
inherit_id refsale.view_order_formThe original view to extend
archXML structureThe changes to apply to the original view

The <sheet position="inside"> element targets the <sheet> tag in the original form view and inserts our new <group> block inside it.


Full Module Layout

md
custom_sale_extension/
├── __init__.py                    # from . import models
├── __manifest__.py                # Module metadata
├── models/
│   ├── __init__.py               # from . import sale_order
│   └── sale_order.py             # _inherit = 'sale.order'
└── views/
    └── sale_order_views.xml      # View inheritance


Installing the Module

  1. Place the custom_sale_extension folder in your Odoo add-ons directory
  2. Restart the Odoo server
  3. Go to Settings > Apps
  4. Click Update App List
  5. Search for Custom Sale Extension
  6. Click Install

To verify the installation worked:

  • Open the Sales module
  • Create or open a Sale Order
  • You should see the Custom Field on the form

Upgrading After Changes

When you modify files in an already-installed module, you need to update it:

bash
# From the Odoo installation directory
./odoo-bin -u custom_sale_extension -d your_database_name

Or from the Odoo UI:

  • Go to Apps
  • Search for your module
  • Click Upgrade (if visible) or use the Technical menu

Extending with More Fields

You can add as many fields as needed:

python
from odoo import models, fields

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    x_custom_field = fields.Char(string="Custom Field")
    x_priority_notes = fields.Text(string="Priority Notes")
    x_external_ref = fields.Char(string="External Reference")
    x_delivery_instructions = fields.Text(string="Delivery Instructions")
    x_is_vip_order = fields.Boolean(string="VIP Order", default=False)

And display them all in the view:

xml
<sheet position="inside">
    <group string="Custom Information">
        <field name="x_custom_field"/>
        <field name="x_external_ref"/>
        <field name="x_is_vip_order"/>
    </group>
    <group string="Notes">
        <field name="x_priority_notes"/>
        <field name="x_delivery_instructions"/>
    </group>
</sheet>


Final Thoughts

Extending the Sale module is a perfect first real-world Odoo development task. It demonstrates the complete workflow: module structure, manifest configuration, model extension via inheritance, and view customization.

The pattern shown here — _inherit the model, extend the view — applies to virtually every Odoo customization you will ever build. Mastering it on the sale module means you can extend any other Odoo module using the exact same approach.

One pattern. Infinite applications.