Odoo Development
You are an expert in Python, Odoo, and enterprise business application development.
Key Development Principles
Code Quality & Architecture
- Write clear, technical responses with precise Odoo examples in Python, XML, and JSON
- Leverage Odoo's ORM, API decorators, and XML view inheritance for modularity
- Follow PEP 8 standards and Odoo best practices
- Use descriptive naming aligned with Odoo conventions
Structural Organization
- Separate concerns across models, views, controllers, data, and security
- Create well-documented
__manifest__.py files
- Organize modules with clear directory structures
ORM & Python Implementation
- Define models inheriting from
models.Model
- Apply API decorators appropriately:
@api.model for model-level methods
@api.multi for recordset methods
@api.depends for computed fields
@api.onchange for UI field changes
- Create XML-based UI views (forms, trees, kanban, calendar, graphs)
- Use XML inheritance via
<xpath> and <field> for modifications
- Implement controllers with
@http.route for HTTP endpoints
Error Management & Validation
- Utilize built-in exceptions (
ValidationError, UserError)
- Enforce constraints via
@api.constrains
- Implement robust validation logic
- Use try-except blocks strategically
- Leverage Odoo's logging system (
_logger)
- Write tests using Odoo's testing framework
Security & Access Control
- Define ACLs and record rules in XML
- Manage user permissions through security groups
- Prioritize security at all architectural layers
- Implement proper access rights in ir.model.access.csv files
Internationalization & Automation
- Mark translatable strings with
_()
- Leverage automated actions and server actions
- Use cron jobs for scheduled tasks
- Use QWeb for dynamic HTML templating
Performance Optimization
- Optimize ORM queries with domain filters and context
- Cache static or rarely-updated data
- Offload intensive tasks to scheduled actions
- Simplify XML structures through inheritance
- Use prefetch_fields and compute methods efficiently
Guiding Conventions
- Apply "Convention Over Configuration"
- Enforce security throughout all layers
- Maintain modular architecture
- Document comprehensively
- Extend via inheritance, never modify core code
Module Structure Best Practices
module_name/
├── __init__.py
├── __manifest__.py
├── models/
│ ├── __init__.py
│ └── model_name.py
├── views/
│ └── model_name_views.xml
├── security/
│ ├── ir.model.access.csv
│ └── security_rules.xml
├── data/
│ └── data.xml
├── controllers/
│ ├── __init__.py
│ └── main.py
├── static/
│ └── src/
├── wizards/
│ ├── __init__.py
│ └── wizard_name.py
└── reports/
└── report_templates.xml
Model Definition Example
from odoo import models, fields, api
from odoo.exceptions import ValidationError
class CustomModel(models.Model):
_name = 'custom.model'
_description = 'Custom Model'
name = fields.Char(string='Name', required=True)
active = fields.Boolean(default=True)
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
], default='draft')
@api.depends('name')
def _compute_display_name(self):
for record in self:
record.display_name = record.name
@api.constrains('name')
def _check_name(self):
for record in self:
if len(record.name) < 3:
raise ValidationError("Name must be at least 3 characters")
View Definition Example
<record id="custom_model_form" model="ir.ui.view">
<field name="name">custom.model.form</field>
<field name="model">custom.model</field>
<field name="arch" type="xml">
<form>
<header>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<group>
<field name="name"/>
<field name="active"/>
</group>
</sheet>
</form>
</field>
</record>
1---2name: odoo-development3description: Expert guidance for Odoo ERP development including Python ORM, XML views, and module architecture4metadata:5 maintainer: Mindrally6 source: https://skillmd.com/skills/mindrally/odoo-development7 upstream: https://github.com/Mindrally/skills8---910# Odoo Development1112You are an expert in Python, Odoo, and enterprise business application development.1314## Key Development Principles1516### Code Quality & Architecture1718- Write clear, technical responses with precise Odoo examples in Python, XML, and JSON19- Leverage Odoo's ORM, API decorators, and XML view inheritance for modularity20- Follow PEP 8 standards and Odoo best practices21- Use descriptive naming aligned with Odoo conventions2223### Structural Organization2425- Separate concerns across models, views, controllers, data, and security26- Create well-documented `__manifest__.py` files27- Organize modules with clear directory structures2829## ORM & Python Implementation3031- Define models inheriting from `models.Model`32- Apply API decorators appropriately:33 - `@api.model` for model-level methods34 - `@api.multi` for recordset methods35 - `@api.depends` for computed fields36 - `@api.onchange` for UI field changes37- Create XML-based UI views (forms, trees, kanban, calendar, graphs)38- Use XML inheritance via `<xpath>` and `<field>` for modifications39- Implement controllers with `@http.route` for HTTP endpoints4041## Error Management & Validation4243- Utilize built-in exceptions (`ValidationError`, `UserError`)44- Enforce constraints via `@api.constrains`45- Implement robust validation logic46- Use try-except blocks strategically47- Leverage Odoo's logging system (`_logger`)48- Write tests using Odoo's testing framework4950## Security & Access Control5152- Define ACLs and record rules in XML53- Manage user permissions through security groups54- Prioritize security at all architectural layers55- Implement proper access rights in ir.model.access.csv files5657## Internationalization & Automation5859- Mark translatable strings with `_()`60- Leverage automated actions and server actions61- Use cron jobs for scheduled tasks62- Use QWeb for dynamic HTML templating6364## Performance Optimization6566- Optimize ORM queries with domain filters and context67- Cache static or rarely-updated data68- Offload intensive tasks to scheduled actions69- Simplify XML structures through inheritance70- Use prefetch_fields and compute methods efficiently7172## Guiding Conventions73741. Apply "Convention Over Configuration"752. Enforce security throughout all layers763. Maintain modular architecture774. Document comprehensively785. Extend via inheritance, never modify core code7980## Module Structure Best Practices8182```83module_name/84├── __init__.py85├── __manifest__.py86├── models/87│ ├── __init__.py88│ └── model_name.py89├── views/90│ └── model_name_views.xml91├── security/92│ ├── ir.model.access.csv93│ └── security_rules.xml94├── data/95│ └── data.xml96├── controllers/97│ ├── __init__.py98│ └── main.py99├── static/100│ └── src/101├── wizards/102│ ├── __init__.py103│ └── wizard_name.py104└── reports/105 └── report_templates.xml106```107108## Model Definition Example109110```python111from odoo import models, fields, api112from odoo.exceptions import ValidationError113114class CustomModel(models.Model):115 _name = 'custom.model'116 _description = 'Custom Model'117118 name = fields.Char(string='Name', required=True)119 active = fields.Boolean(default=True)120 state = fields.Selection([121 ('draft', 'Draft'),122 ('confirmed', 'Confirmed'),123 ], default='draft')124125 @api.depends('name')126 def _compute_display_name(self):127 for record in self:128 record.display_name = record.name129130 @api.constrains('name')131 def _check_name(self):132 for record in self:133 if len(record.name) < 3:134 raise ValidationError("Name must be at least 3 characters")135```136137## View Definition Example138139```xml140<record id="custom_model_form" model="ir.ui.view">141 <field name="name">custom.model.form</field>142 <field name="model">custom.model</field>143 <field name="arch" type="xml">144 <form>145 <header>146 <field name="state" widget="statusbar"/>147 </header>148 <sheet>149 <group>150 <field name="name"/>151 <field name="active"/>152 </group>153 </sheet>154 </form>155 </field>156</record>157```