odoo-code-review
The Odoo domain lens over module and addon code, in addition to a generic review and never instead. Covers ORM anti-patterns, sudo() misuse, raw-SQL injection, N+1 and prefetch, ir.model.access.csv, record rules, upgrade safety, untranslated strings.
- License 许可
- MIT
- 最近更新
- 2026-11-02
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- odoo-code-review
- description
- The Odoo domain lens over module and addon code, in addition to a generic review and never instead. Covers ORM anti-patterns, sudo() misuse, raw-SQL injection, N+1 and prefetch, ir.model.access.csv, record rules, upgrade safety, untranslated strings.
- user-invocable
- false
03 SKILL.md 正文
Odoo code review checklist
State the target Odoo version and edition first. They decide which APIs are valid. Review the diff against every group below. Flag the file and the line; cite the version rule when one applies.
ORM anti-patterns
- Writes or creates inside a loop over records. Batch: build a list of vals and
create([...]), orrecordset.write({...})once. search()orbrowse()inside a loop. Pull the data once, thenfilteredormapped.- A related field read per record in a loop instead of
mapped()orread_group(). - A recordset mutated while iterated.
.idor.idswhere a recordset is expected, or the reverse.- Business logic that bypasses the ORM, so computes, constraints and rules never fire.
N+1 and prefetch
- Loops that defeat prefetch (
record.partner_id.nameone record at a time after breaking the recordset apart). - Aggregations in Python that
read_groupdoes in one query. - A computed field without
store=Truethat is searched, grouped or sorted on. - Missing or wrong
@api.depends: stale computes or over-recomputation. - No
index=Trueon a frequently searched field.
sudo() misuse
sudo()used to dodge an access error instead of fixing access rights or record rules. It bypasses record rules: privilege escalation and data leak.sudo()spanning more than the minimal operation that needs it.- User-supplied data written under
sudo()without a re-check of authorization. sudo()wherewith_companyorwith_contextwas the real intent.
Raw SQL and injection
self.env.cr.execute(...)with f-strings,%or.format(). Parameterize:cr.execute("... WHERE id = %s", (value,)).- Table or column names interpolated from input.
- Raw SQL that skips access rules where the ORM fits. Justified raw SQL names its security implication.
- Reads that bypass multi-company or record-rule scoping.
Security: access rights and record rules
- A new model without an
ir.model.access.csventry. - Over-broad access (write or unlink to
base.group_user) where a narrower group fits. - Missing
ir.rulefor multi-company or per-user data. The domain must scope what it claims. - Menus or actions exposed without a matching
groupsrestriction.
Upgrade safety
- Deprecated or removed decorators and APIs for the target version (
@api.oneremoved in 12.0;@api.multia no-op from 13.0 and removed in 14.0; pre-8.0_columns). Confirm each against the target version before you flag it. - Hardcoded database ids instead of
self.env.ref('module.xml_id'). - Data records without
noupdatewhere they must survive a module upgrade. - A field or model rename without a migration script.
- Overrides of core methods whose signature changed across versions.
- Manifest: correct
dependsandversion, no stale dependency.
Translations
- User-facing strings not wrapped in
_(). - f-strings or concatenation inside
_(). Use_("Hello %(name)s", name=name). - Field
stringandhelpand error messages left untranslated for a multilingual client.
Views and QWeb
- View or field references to models or fields that do not exist.
t-rawor unsafe QWeb rendering of user data (XSS).- An inherited view with a brittle
xpath(position selectors).
Function length
- A function above 25 logical lines of code is a finding. One statement is one logical line; comments do not count.
- Name the join point between responsibilities where a helper comes out. Long
createandwriteoverrides and compute methods are the usual offenders.
Output
One line per finding: file:line · group · severity · what is wrong · version rule.
Severity is blocker, high, medium or low.
Stop conditions
- Report nothing this checklist does not cover. Keep the review Odoo-specific.
- Never flag an API as wrong without the version rule. "Removed in 13.0" is a finding; "looks old" is not.
- Never approve
sudo()or raw SQL because it works. State the security implication. - Never invent the Odoo version. When it is not given, state the assumption and mark version-specific findings conditional.
04 同仓库更多 Skills
report-incident
Draft a terse GitHub issue for an incident in the Odoo dev suite (odoo-dev, odoo-orchestrator, dispatcher), with a current environment block and no private data. Files it only after you approve. Use when a tool or workflow failed.
principles
Engineering principles indexed as one-liners: safety and correctness, design and architecture, composition and interfaces, code structure, performance, visibility. Use when writing new code, reviewing a diff, or justifying a design choice.
odoo-upgrade
Plan and run code upgrades of custom Odoo modules between major versions (16.0→17.0→18.0→19.0). Use to migrate or port a module or addon, for breaking changes, a module inventory, or an upgrade estimate or plan.
odoo-upgrade-project
Human SOP for a whole Odoo upgrade project past the code port: staging database upgrade through upgrade.odoo.com, on-prem restore, cutover, go-live, support tickets and functional requirements. A planning reference.
odoo-test-run
Run an Odoo module's unit tests and HttpCase browser tours on a throwaway database and return machine-checkable evidence: tests executed, tours executed, failure lines. Use before a PR, after a fix, or when a green run never said how many tests ran.
odoo-task-env
Stand up the working environment for one Odoo task: find work that already exists, create or reuse an isolated git worktree on the task branch, bring a runnable stack up. Use at the START of implementing any task, and whenever one is picked back up.