Odoo orm expert

From sickn33/agentic-awesome-skills · View interactive version

Odoo orm expert is an AI agent skill from the GitHub repository sickn33/agentic-awesome-skills. Master Odoo ORM patterns: search, browse, create, write, domain filters, computed fields, and performance-safe query techniques.

How to use this skill

Skill file

Odoo ORM Expert

Overview

This skill teaches you Odoo's Object Relational Mapper (ORM) in depth. It covers reading/writing records, building domain filters, working with relational fields, and avoiding common performance pitfalls like N+1 queries.

When to Use This Skill

How It Works

  1. Activate: Mention @odoo-orm-expert and describe what data operation you need.
  2. Get Code: Receive correct, idiomatic Odoo ORM code with explanations.
  3. Optimize: Ask for performance review on existing ORM code.

Examples

Example 1: Search with Domain Filters

# Find up to 50 confirmed sale orders for a specific customer dated this UTC year
import datetime

year = datetime.datetime.now(datetime.timezone.utc).year
start_of_year = datetime.datetime(year, 1, 1)  # Odoo stores naive UTC datetimes
start_of_next_year = datetime.datetime(year + 1, 1, 1)

orders = self.env['sale.order'].search([
    ('partner_id', '=', partner_id),
    ('state', '=', 'sale'),
    ('date_order', '>=', start_of_year),
    ('date_order', '<', start_of_next_year),
], order='date_order desc', limit=50)

# date_order is a Datetime field. For precise business-year boundaries,
# construct UTC datetime bounds from the intended business timezone;
# this example uses the UTC calendar year.

Example 2: Computed Field

total_order_count = fields.Integer(
    string='Total Orders',
    compute='_compute_total_order_count',
    store=True
)

@api.depends('sale_order_ids')
def _compute_total_order_count(self):
    for record in self:
        record.total_order_count = len(record.sale_order_ids)

Example 3: Safe Bulk Write (avoid N+1)

# Batch writes reduce repeated calls, but can trigger additional compute/tracking queries
partners = self.env['res.partner'].browse(approved_partner_ids).exists()  # Explicit scoped IDs
partners.write({'country_id': self.env.ref('base.us').id})

# ❌ BAD: Triggers a separate query per record
for partner in partners:
    partner.country_id = self.env.ref('base.us').id

Best Practices

Limitations

Examples are model-method fragments requiring imports, record definitions and authorized scope. Do not infer missing country data means US; write only confirmed values to selected records. sudo() bypasses access rules and requires a justified boundary. Batch operations do not guarantee one SQL query, and mapped/filtered may load large recordsets; profile actual query counts and test record-rule/multi-company isolation.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.