odoo-code-review
Odoo Code Reviewer
Python Guidelines
General
- PEP8: Strictly follow PEP8 (120 chars line length is often acceptable in Odoo).
- Imports:
odooimports first.from odoo import models, fields, api, _from odoo.exceptions import UserError, ValidationError
ORM Methods
- Search: Use
search_count()instead oflen(search()). - Filtered: Use
filtered()for in-memory filtering of recordsets. - Mapped: Use
mapped()to extract values. - Write/Create: Batch operations where possible.
- SQL: Avoid direct SQL (
self.env.cr.execute) unless absolutely necessary for performance. If used, never inject variables directly; use parameters.
Fields & Models
- Naming:
- Fields:
snake_case. Many2one fields usually end with_id(e.g.,partner_id). - One2many/Many2many: usually plural (e.g.,
line_ids,tag_ids).
- Fields:
- Computed Fields: Always add
@api.depends. - Constrains: Use
@api.constrainsfor data integrity checks. - Translations: Wrap user-facing strings in
_().
XML Guidelines
Views
- Records: Use
<record id="..." model="ir.ui.view">. - Arch: All views must have an
<arch type="xml">block. - XPath: Use concise XPath expressions. Prefer
nameattributes over indices.- Bad:
//field[3] - Good:
//field[@name='description']
- Bad:
- Attributes:
invisible: Use strictly for hiding.readonly: For uneditable fields.required: For mandatory fields.
- Noids: Avoid hardcoded database IDs. Use
ref="module.xml_id".
Data Files
- NoUpdate: Use
noupdate="1"in<data>for data that shouldn't be reset on upgrade (like sequence numbers or cron jobs).
Manifest (manifest.py)
- Ensure
dependslists all required modules. - Ensure
datalists all XML/CSV files in correct order (security -> views -> data). - Ensure
licenseis specified (e.g., LGPL-3).
Review Checklist
- Security: Are access rights (ir.model.access.csv) defined?
- Performance: Are there loops doing SQL queries inside? (N+1 problem).
- Upgrade: Will this code break on module update?
- Idempotency: Can this XML be loaded multiple times without duplicating data?
More from nguyenhuy158/skills
copilot-commit-style
Use this skill when the user asks to write, generate, draft, or format a git commit message. It enforces the Conventional Commits specification with mandatory emojis and strict formatting rules.
9git-branch-clean
Use this skill when user wants to clean up local git branches whose remote tracking branches are gone/deleted. Triggers on phrases like "clean branches", "delete stale branches", "prune branches", "git branch clean", "dọn branch", "xóa branch cũ".
3pr-creator
Use this skill when user wants to create a pull request (PR) from current branch to another branch. Triggers on phrases like "create PR", "open PR", "make pull request", "tạo PR", "tạo pull request".
3code-polish
Polish Python code in git-changed files. Removes all comments and docstrings, eliminates magic strings and numbers, makes code self-documenting via naming. Python only — skips other languages. Use when user says "code-polish", "polish code", "clean code", "self-documenting", "remove comments", "làm sạch code".
2