Upgrading an Odoo Module from Version 15 to Version 18: A Step-by-Step Tutorial with Example
Upgrading an Odoo module from version odoo15 to version odoo18 requires careful adjustments to ensure compatibility with changes introduced in newer versions of Odoo. This detailed tutorial provides a step-by-step guide with examples for upgrading your odoo module.
Prerequisites
- Odoo 15 module code.
- Odoo 18 development environment.
- Basic knowledge of Python, XML, and Odoo framework.
- Code editor (e.g., VSCode, PyCharm).
- Test database for Odoo 18.
Step 1: Set Up the Odoo 18 Development Environment
Ensure you have Odoo 18 installed and running on your system. Use a virtual environment to manage Python dependencies.
# Create virtual environment
python3 -m venv odoo18-env
source odoo18-env/bin/activate
# Install required Python packages
pip install -r requirements.txt
# Run Odoo 18
python odoo-bin -c your/odoo.config
Step 2: Update the __manifest__.py
File
The manifest file contains metadata about your module. You need to update the version number and dependencies.
Original __manifest__.py
(Odoo 15):
{
'name': 'Custom Module',
'version': '0.1',
'depends': ['base', 'sale'],
'data': [
'security/ir.model.access.csv',
'views/custom_view.xml',
],
}
Updated __manifest__.py
(Odoo 18):
{
'name': 'Custom Module',
'version': '18.0.1.0.0',
'depends': ['base', 'sale'],
'data': [
'security/ir.model.access.csv',
'views/custom_view.xml',
],
'application': True,
}
Changes:
- Updated
version
to18.0.1.0.0
. - Added
application
key for better module categorization.
Step 3: Update Python Code for Models
Odoo’s ORM may introduce changes in method signatures and field definitions.
Example: Updating a Model
Original Model (models/custom_model.py
- Odoo 15):
from odoo import models, fields
class CustomModel(models.Model):
_name = 'custom.model'
_description = 'Custom Model'
name = fields.Char(string='Name', required=True)
amount = fields.Float(string='Amount')
Updated Model (models/custom_model.py
- Odoo 18):
from odoo import models, fields, api
class CustomModel(models.Model):
_name = 'custom.model'
_description = 'Custom Model'
name = fields.Char(string='Name', required=True)
amount = fields.Float(string='Amount')
active = fields.Boolean(string='Active', default=True)
@api.model
def create(self, vals):
# Add custom logic if needed
return super(CustomModel, self).create(vals)
Changes:
- Added a new field
active
to align with best practices. - Updated the
create
method using@api.model
decorator.
Step 4: Update XML Files
Changes in the XML structure or field attributes may be required to comply with Odoo 18.
Original View (views/custom_view.xml
- Odoo 15):
<odoo>
<record id="view_custom_model_tree" model="ir.ui.view">
<field name="name">custom.model.tree</field>
<field name="model">custom.model</field>
<field name="arch" type="xml">
<tree string="Custom Model">
<field name="name"/>
<field name="amount"/>
</tree>
</field>
</record>
</odoo>
Updated View (views/custom_view.xml
- Odoo 18):
<odoo>
<record id="view_custom_model_tree" model="ir.ui.view">
<field name="name">custom.model.tree</field>
<field name="model">custom.model</field>
<field name="arch" type="xml">
<list string="Custom Model">
<field name="name"/>
<field name="amount"/>
<field name="active"/>
</list>
</field>
</record>
</odoo>
Changes:
- Added the new
active
field to the tree view. - Replace your xml
tree
tolist
.
Step 5: Update Security Rules
Ensure that access rights and record rules are updated.
Original Security Rule (security/ir.model.access.csv
- Odoo 15):
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_custom_model,access.custom.model,model_custom_model,base.group_user,1,1,1,1
Updated Security Rule (Odoo 18)
No major changes are required unless new groups or models are introduced.
Step 6: Test the Module
- Upgrade the module:
python odoo-bin -c your/odoo.config -u custom_module
2. Check logs for any warnings or errors.
3. Test functionality to ensure everything works as expected.
Step 7: Fix Issues and Perform Final Testing
Address any issues encountered during testing, including:
- Missing fields or views.
- Incorrect method overrides.
- Security rule errors.
Step 8: Deploy the Upgraded Module
Once everything is working correctly, deploy the upgraded module to the production environment.
Summary
Upgrading an Odoo module involves:
- Updating the manifest file.
- Adjusting Python models and methods.
- Modifying XML views.
- Reviewing and updating security rules.
- Thoroughly testing the module.
By following this step-by-step guide, you can upgrade your module from Odoo 15 to Odoo 18 with minimal issues.