Skill

Master Odoo ORM for Efficient Data Operations

An Odoo ORM skill covering record CRUD, domain filters, computed fields, and avoiding N+1 query performance pitfalls.

Works with odoo

84
Spark score
out of 100
Updated last month
Version 13.1.1

Add to Favorites

Why it matters

Leverage Odoo's Object Relational Mapper (ORM) to efficiently read, write, and manipulate data. This skill provides expert guidance on building complex queries, optimizing performance, and avoiding common pitfalls in Odoo development.

Outcomes

What it gets done

01

Write and optimize Odoo ORM methods like search(), create(), write(), and unlink().

02

Construct sophisticated domain filters for Odoo views and server actions.

03

Implement and debug computed, stored, and related fields.

04

Identify and resolve performance bottlenecks, including N+1 query issues.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-odoo-orm-expert | bash

Overview

Odoo ORM Expert

This skill covers Odoo ORM patterns: record CRUD via search/browse/create/write/unlink, domain filter construction, computed and stored fields, and avoiding N+1 query performance issues in bulk operations. Use it when writing or optimizing Odoo ORM code - CRUD, domain filters, computed fields, or bulk operations. Does not cover raw SQL, field partitioning at scale, or transient/wizard models.

What it does

This skill teaches Odoo's ORM in depth: reading and writing records via search(), browse(), create(), write(), and unlink(); building domain filters for views and server actions; implementing computed, stored, and related fields; and avoiding common performance pitfalls like N+1 queries. Worked examples cover a domain-filtered search for confirmed sale orders within a date range, with the crucial gotcha that dates must be passed as 'YYYY-MM-DD' strings in domain tuples rather than Python date or datetime objects, since the ORM serializes strings correctly but not raw date objects; a computed, stored field such as total_order_count recalculated via @api.depends on a related one2many field; and a bulk-write pattern that updates an entire recordset in a single write() call instead of looping and writing per record, which triggers a separate query for every record in the loop.

When to use - and when NOT to

Use it when writing search, browse, create, write, or unlink calls, building complex domain filters, implementing computed, stored, or related fields, or debugging slow queries and optimizing bulk operations. It does not cover cr.execute() raw SQL patterns in depth - use the Odoo performance tuner skill instead for SQL-level optimization - nor partitioning strategies for stored computed fields at scale, nor transient models (models.TransientModel) or wizard patterns. It also notes that ORM behavior can differ slightly between Odoo SaaS and On-Premise due to configuration overrides.

Inputs and outputs

Given a description of the desired data operation, it produces correct, idiomatic Odoo ORM code with explanations, or a performance review of existing ORM code that flags anti-patterns like calling search() inside a loop.

Integrations

Targets the Odoo ORM API directly - recordset methods like mapped(), filtered(), sorted(), search_count(), and with_context() - with no external tooling required beyond an Odoo instance or module to run the generated code against. These recordset methods are meant to replace manual Python loops over records: mapped() extracts a field's values (or chains through relations) across an entire recordset in one call, filtered() narrows a recordset by a condition without a manual list comprehension, and sorted() orders a recordset by a key function, all evaluated by the ORM rather than iterated in application code.

Who it's for

Odoo developers writing or optimizing module code who need idiomatic ORM patterns and a checklist of common performance killers - search() inside a loop, raw datetime objects in domains, unnecessary sudo() use, and len(search()) instead of search_count() - to catch before shipping. Activation is straightforward: mention @odoo-orm-expert with a description of the data operation needed, receive idiomatic code with explanations, and optionally ask for a targeted performance review of existing ORM code afterward.

Source README

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.

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.