Build Custom Module Step-by-Step
First, Odoo 18 tutorial module shows you how to create a custom add-on from scratch. First, we set up a development environment and clone Odoo 18. Next, we generate a module skeleton under addons/. Additionally, we define a manifest file and Python package. Moreover, we create models and fields for a real-estate example. Finally, we link to the official Odoo documentation for deeper reference.
In this guide, we walk you through an Odoo 18 module tutorial. We use active voice and clear steps. Moreover, we include every code snippet with explanations. Thus, you can follow along and build your own Odoo 18 custom module in English.
Odoo 18 tutorial module: Setup Your Development Environment
First, we prepare our system for Odoo 18 development. Moreover, we ensure we use a clean Python environment.
Install Odoo 18 from Source
- First, we clone the official Odoo 18 repository.
git clone https://github.com/odoo/odoo.git --branch 18.0 --depth 1 - Next, we install system dependencies (Debian/Ubuntu example).
sudo apt update && \ sudo apt install -y python3-pip python3-dev libxml2-dev libxslt1-dev \ libjpeg-dev libpq-dev build-essential - Then, we install PostgreSQL and create a user.
sudo apt install -y postgresql sudo -u postgres createuser --createdb $USER
Create a Python Virtual Environment
Next, we isolate dependencies with venv.
cd odoo
python3 -m venv venv
source venv/bin/activate
pip install wheel
pip install -r requirements.txt
After that, we confirm the installation:
which python
python --version
Odoo 18 tutorial module: Create Module Skeleton
Now, we generate a custom module under addons/real_estate. Moreover, we follow Odoo conventions.
mkdir -p odoo/addons/real_estate
cd odoo/addons/real_estate
Define the Manifest (__manifest__.py)
First, we create __manifest__.py to describe our module.
# real_estate/__manifest__.py
{
"name": "Real Estate",
"version": "1.0.0",
"category": "Sales",
"summary": "Manage real estate properties",
"description": """
This module allows you to manage properties,
prices, currencies, and countries.
""",
"author": "Your Name",
"depends": ["base"],
"data": [
"views/real_estate_views.xml",
"security/ir.model.access.csv",
],
"installable": True,
"application": True,
"license": "LGPL-3",
}
Then, we save the file and proceed.
Initialize the Python Package (__init__.py)
Next, we create an __init__.py file to load our models.
# real_estate/__init__.py
from . import models
And we create a models/ directory:
mkdir models
touch models/__init__.py
Odoo 18 tutorial module: Define Models and Fields
Now, we write Python code to define our data structures.
Create models/real_estate.py
We start by creating the model file:
# real_estate/models/real_estate.py
from odoo import models, fields, api
class RealEstate(models.Model):
_name = "real.estate"
_description = "Real Estate Property"
Add Fields for Real Estate Model
Next, we add fields for property title, description, price, currency, and country:
name = fields.Char(
string="Title",
required=True,
help="Enter the property title",
)
description = fields.Text(
string="Description",
help="Add a brief description",
)
price = fields.Float(
string="Price",
required=True,
help="Set the property price",
)
currency_id = fields.Many2one(
comodel_name="res.currency",
string="Currency",
default=lambda self: self.env.company.currency_id,
help="Select the currency",
)
country_id = fields.Many2one(
comodel_name="res.country",
string="Country",
help="Select the country",
)
Moreover, we ensure we import this file in models/__init__.py:
# real_estate/models/__init__.py
from . import real_estate
Odoo 18 tutorial module: Create Views for Your Model
Next, we design the user interface. Moreover, we use XML views.
Define Tree and Form Views
We create views/real_estate_views.xml:
<!-- real_estate/views/real_estate_views.xml -->
<odoo>
<!-- Tree view -->
<record id="view_real_estate_tree" model="ir.ui.view">
<field name="name">real.estate.tree</field>
<field name="model">real.estate</field>
<field name="arch" type="xml">
<tree string="Properties">
<field name="name"/>
<field name="price"/>
<field name="currency_id"/>
<field name="country_id"/>
</tree>
</field>
</record>
<!-- Form view -->
<record id="view_real_estate_form" model="ir.ui.view">
<field name="name">real.estate.form</field>
<field name="model">real.estate</field>
<field name="arch" type="xml">
<form string="Property">
<sheet>
<group>
<field name="name"/>
<field name="description"/>
</group>
<group>
<field name="price"/>
<field name="currency_id"/>
<field name="country_id"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
Add Menu and Action Entries
Next, we add an action and menu item:
<!-- real_estate/views/real_estate_action_menu.xml -->
<odoo>
<record id="action_real_estate" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">real.estate</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_real_estate_root"
name="Real Estate"
sequence="10"
parent="base.menu_custom"/>
<menuitem id="menu_real_estate"
name="Properties"
sequence="1"
parent="menu_real_estate_root"
action="action_real_estate"/>
</odoo>
Moreover, we include both XML files in our manifest’s data list.
Odoo 18 tutorial module: Install and Test Your Module
First, we restart the Odoo server:
./odoo-bin -c /etc/odoo.conf --addons-path=addons,odoo/addons
Next, we update the apps list:
- Navigate to Apps in the Odoo UI.
- Click Update Apps List.
- Search for Real Estate.
- Click Install.
Meanwhile, we test our module:
- We create a new property.
- We fill in the title, price, currency, and country.
- We save and verify the data.
Odoo 18 tutorial module: Add Advanced Features
Next, we enhance our module with advanced concepts. Moreover, we follow best practices.
Inheritance and Extension
First, we show how to inherit from res.partner to add a boolean field:
# real_estate/models/res_partner_inherit.py
from odoo import models, fields
class Partner(models.Model):
_inherit = "res.partner"
is_property_owner = fields.Boolean(
string="Property Owner",
default=False,
help="Check if the partner owns a property",
)
Next, we include this file in models/__init__.py:
from . import real_estate
from . import res_partner_inherit
Computed and Related Fields
Furthermore, we add a computed field to calculate tax on price:
# real_estate/models/real_estate.py (append)
class RealEstate(models.Model):
_inherit = "real.estate"
tax_rate = fields.Float(
string="Tax Rate",
default=0.10,
help="Set default tax rate",
)
price_with_tax = fields.Float(
string="Price with Tax",
compute="_compute_price_with_tax",
store=True,
)
@api.depends('price', 'tax_rate')
def _compute_price_with_tax(self):
for rec in self:
rec.price_with_tax = rec.price * (1 + rec.tax_rate)
Thus, Odoo computes tax automatically.
Security Access Control
Additionally, we define basic access rights in security/ir.model.access.csv:
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_real_estate_user","real.estate user","model_real_estate","base.group_user",1,1,1,0
Thus, we protect our data with standard Odoo groups.
Odoo 18 tutorial module: Deploy and Upgrade
Finally, we prepare our module for deployment:
- First, we commit changes and push to a private Git repository.
- Next, we tag a release (e.g.,
v1.0.0).git tag v1.0.0 git push origin v1.0.0 - Then, we update the module on the production server via pull and upgrade:
./odoo-bin -c /etc/odoo.conf -u real_estate
Moreover, we monitor logs and verify that no errors occur.
Conclusion
In this Odoo 18 tutorial module, we created a real-estate add-on from zero. First, we set up a clean environment. Next, we built the module skeleton with manifest and initialization. Then, we defined models, fields, and views. Additionally, we added inheritance, computed fields, and security rules. Finally, we deployed and upgraded our module.
Thus, you can use this module tutorial for Odoo 18 as a template for any custom app. Moreover, you can extend the example to support contacts, leads, and reporting. Finally, you can explore more at the Odoo developer guide and adapt this Odoo 18 module tutorial to your own business needs.
Discover more from teguhteja.id
Subscribe to get the latest posts sent to your email.


Pingback: Odoo Real Estate Management: 7 Proven Ways to Skyrocket Sales Fast