odoo-orm-expert – skill Viết lách & Nội dung cho agent AI
Nắm vững các mẫu ORM của Odoo: search, browse, create, write, domain filter, computed field và kỹ thuật truy vấn an toàn về hiệu năng.
Cài skill odoo-orm-expert bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/odoo-orm-expert-09cb4.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /odoo-orm-expert – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/odoo-orm-expert-09cb4.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $odoo-orm-expert – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/odoo-orm-expert-09cb4.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /odoo-orm-expert – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/odoo-orm-expert-09cb4.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /odoo-orm-expert – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
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
- Writing
search(),browse(),create(),write(), orunlink()calls. - Building complex domain filters for views or server actions.
- Implementing computed, stored, and related fields.
- Debugging slow queries or optimizing bulk operations.
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').idBest Practices
- ✅ Do: Use
mapped(),filtered(), andsorted()on recordsets instead of Python loops. - ✅ Do: Use
sudo()sparingly and only when you understand the security implications. - ✅ Do: Prefer
search_count()overlen(search(...))when you only need a count. - ✅ Do: Use
with_context(...)to pass context values cleanly rather than modifyingself.env.contextdirectly. - ❌ Don't: Call
search()inside a loop — this is the #1 Odoo performance killer. - ❌ Don't: Use raw SQL unless absolutely necessary; use ORM for all standard operations.
- ✅ Do: Match values to the field type: Date uses dates or server date strings; Datetime uses datetimes or server datetime strings. Python date/datetime objects are supported; do not truncate a datetime to a date or mix the two types when comparing. See the [Odoo ORM date/time guidance](https://www.odoo.com/documentation/17.0/developer/reference/backend/orm.html).
Limitations
- Does not cover
cr.execute()raw SQL patterns in depth — use the Odoo performance tuner skill for SQL-level optimization. - Stored computed fields can cause significant write overhead at scale; this skill does not cover partitioning strategies.
- Does not cover transient models (
models.TransientModel) or wizard patterns. - ORM behavior can differ slightly between Odoo SaaS and On-Premise due to config overrides.
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.
Skill liên quan
- odoo-performance-tuner – Hướng dẫn chuyên sâu chẩn đoán và khắc phục sự cố hiệu năng Odoo: truy vấn chậm, cấu…
- odoo-upgrade-advisor – Trợ lý nâng cấp phiên bản Odoo từng bước: checklist trước nâng cấp, lộ trình nâng cấp…
- onboarding – Khi người dùng muốn tối ưu onboarding sau đăng ký, kích hoạt người dùng, trải nghiệm lần…
- php-pro – Viết code PHP đúng chuẩn idiom với generator, iterator, cấu trúc dữ liệu SPL và tính…
- plan-writing – Lập kế hoạch tác vụ có cấu trúc với phân rã rõ ràng, phụ thuộc và tiêu chí kiểm chứng…
- podcast-generation – Tạo bản thuyết minh âm thanh thật từ nội dung văn bản bằng Realtime API của Azure OpenAI.
- post – Tạo bộ hình ảnh chia sẻ trông tự nhiên: carousel Xiaohongshu, ảnh X, ảnh bìa, bố cục…
- postel-writing – Soạn bài đăng X (Twitter) hoặc LinkedIn theo giọng riêng của người dùng, nghiên cứu các…