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 thesale.ordermodel - Displays the field on the sale order form view
- Demonstrates the full Extension Inheritance workflow
Module Directory Structure
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.
{
'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.0prefix indicates compatibility with Odoo 17depends:['sale']means the Sale module must be installed firstdata: lists all XML files to load during installation — the order mattersapplication: Falsemeans 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:
from . import models
Without this, Odoo will not load any of your Python code.
Step 3: Models `__init__.py`
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.
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 existingsale.ordermodel- No
_nameis defined — this means we are not creating a new model, just extending the existing one x_custom_fieldis a new column that will be added to thesale_orderdatabase 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:
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.
<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
| Attribute | Value | Description |
|---|---|---|
id | view_order_form_inherit_custom | Unique ID for this view record |
model | ir.ui.view | We are creating a view record |
name | sale.order.form.inherit.custom | Name of the inherited view |
model (field) | sale.order | The model this view applies to |
inherit_id ref | sale.view_order_form | The original view to extend |
arch | XML structure | The 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
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
- Place the
custom_sale_extensionfolder in your Odoo add-ons directory - Restart the Odoo server
- Go to Settings > Apps
- Click Update App List
- Search for
Custom Sale Extension - 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:
# 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:
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:
<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.