Introduction:
Odoo is a powerful open-source ERP system that allows businesses to customize and extend its functionalities through modules. If you need a specific feature that Odoo doesn’t offer out-of-the-box, you can create a custom module. In this guide, we will walk through the process of developing a custom Odoo module from scratch.
Step 1: Set Up Your Odoo Development Environment
Before you start developing, you need to set up your environment correctly.
Prerequisites
- Python 3.8+
- PostgreSQL
- Odoo installed (e.g., Odoo 17)
- A code editor (VS Code, PyCharm, etc.)
- Basic knowledge of Python and XML
If you haven’t installed Odoo yet, follow these steps:
# Update your system
sudo apt update && sudo apt upgrade -y
# Install dependencies
sudo apt install python3 python3-pip python3-venv build-essential libpq-dev -y
# Install PostgreSQL
sudo apt install postgresql -y
# Create a PostgreSQL user for Odoo
sudo -u postgres createuser -s odoo
After setting up Odoo, make sure it runs correctly before proceeding.
Step 2: Create the Module Structure
Navigate to the Odoo add-ons directory and create a new module folder.
cd /odoo/custom_addons/
mkdir my_custom_module
cd my_custom_module
Inside this folder, create the following structure:
my_custom_module/
├── __init__.py
├── __manifest__.py
├── models/
│ ├── __init__.py
│ ├── my_model.py
├── views/
│ ├── my_model_views.xml
└── security/
├── ir.model.access.csv
Step 3: Define the Module Metadata
Open __manifest__.py
and define the module information:
{
'name': 'My Custom Module',
'version': '1.0',
'summary': 'A custom module for demonstration purposes.',
'author': 'Your Name',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/my_model_views.xml',
],
'installable': True,
'application': True,
}
This manifest file contains essential metadata like module name, dependencies, and data files.
Step 4: Create the Model (Database Table)
Odoo models define database tables. Open models/my_model.py
and create a model:
This model creates a database table my_model
with fields for name
, description
, and active
status.
Step 5: Define Access Rights
Odoo requires access control for models. Create security/ir.model.access.csv
and define user permissions:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_my_model,my.model,model_my_model,,1,1,1,1
This file grants full access to all users.
Step 6: Create the Views
Views define how models appear in the Odoo UI. Open views/my_model_views.xml
and add:
This file defines form and tree views for the model.
Step 7: Load the Module in Odoo
Now, install the module:
- Restart Odoo:
sudo systemctl restart odoo
- Activate Developer Mode in Odoo.
- Navigate to Apps > Update Apps List.
- Search for
My Custom Module
and click Install.
Step 8: Test the Module
After installation, go to My Models in the Odoo UI. You should be able to:
- Create new records.
- Edit existing records.
- Delete records.
If anything doesn’t work, check Odoo logs:
sudo journalctl -u odoo --no-pager -n 100
Looking for server based install of odoo server, please refer my old blog with full detail.
Hope you find this helpful!!!
Contact us for odoo consulting, we will assist you..
How to Develop a Custom Odoo Module from Scratch