Awesome-omni-skill Creating Models
Step-by-step guide to create a new Odoo model with fields, constraints, and methods.
install
source · Clone the upstream repo
git clone https://github.com/diegosouzapw/awesome-omni-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/machine-learning/creating-models" ~/.claude/skills/diegosouzapw-awesome-omni-skill-creating-models && rm -rf "$T"
manifest:
skills/machine-learning/creating-models/SKILL.mdsource content
Creating Odoo Models
Steps
-
Create the Python file in
directory (e.g.models/
).models/my_model.py -
Define the model class:
from odoo import models, fields, api, _ from odoo.exceptions import ValidationError class MyModel(models.Model): _name = 'my.model' _description = 'My Model' _order = 'sequence, name' name = fields.Char(string='Name', required=True) sequence = fields.Integer(default=10) active = fields.Boolean(default=True) state = fields.Selection([ ('draft', 'Draft'), ('confirmed', 'Confirmed'), ('done', 'Done'), ], default='draft', string='Status', tracking=True) partner_id = fields.Many2one('res.partner', string='Partner') line_ids = fields.One2many('my.model.line', 'model_id', string='Lines') tag_ids = fields.Many2many('my.model.tag', string='Tags') total = fields.Float(compute='_compute_total', store=True) @api.depends('line_ids.amount') def _compute_total(self): for record in self: record.total = sum(record.line_ids.mapped('amount')) @api.constrains('name') def _check_name(self): for record in self: if record.name and len(record.name) < 3: raise ValidationError(_("Name must be at least 3 characters.")) def action_confirm(self): self.write({'state': 'confirmed'}) -
Register in
: Add__init__.py
infrom . import my_model
.models/__init__.py -
Add to manifest: Ensure
is imported in the module's rootmodels/
.__init__.py -
Add security: Create ACL in
.security/ir.model.access.csv -
Create views: Add form and list views in
.views/my_model_views.xml
Checklist
-
and_name
set_description - Fields defined with proper types and attributes
- Computed fields have
@api.depends - Constraints use
@api.constrains - Model registered in
chain__init__.py - ACL entry in
ir.model.access.csv - Views created (at minimum form + list)
- Added to
data list__manifest__.py