T08: Odoo 19 Multi-company Models — Không có company_id
Vấn đề
Trong Odoo 19, một số model quan trọng KHÔNG có field company_id trực tiếp:
| Model | company_id? | Ghi chú |
|-------|-------------|---------|
| account.account | KHÔNG | COA dùng allowed_company_ids context |
| product.category | KHÔNG | Shared across companies |
| product.template | KHÔNG | Shared, company filter qua context |
| res.company | id (bản thân) | Không dùng company_id domain |
Triệu chứng
ValueError: Invalid field account.account.company_id in condition ('company_id', '=', 6)
Hoặc JSON-2 endpoint trả 500 Internal Server Error khi query các model trên.
Giải pháp
1. Dùng allowed_company_ids context thay vì domain filter
❌ SAI — Odoo 19 raise ValueError
records = client.search_read('account.account', [
('company_id', '=', company_id),
], ['code'])
✅ ĐÚNG — dùng context
ctx = {'allowed_company_ids': [company_id]}
records = xmlrpc_search_read('account.account', [], ['code'],
context=ctx)
2. Dùng XML-RPC thay JSON-2 cho multi-company models
JSON-2 endpoint (/web/dataset/call_kw) không hỗ trợ allowed_company_ids context đúng cách → phải dùng XML-RPC (/xmlrpc/2/object + execute_kw).
import xmlrpc.client
common = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/common")
uid = common.authenticate(db, user, api_key, {})
models = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/object")
search_read với context
result = models.execute_kw(db, uid, api_key, 'account.account',
'search_read', [[]],
{'fields': ['code'], 'limit': 500,
'context': {'allowed_company_ids': [6]}})
3. Lock Date field đổi tên
❌ SAI — Odoo 19 không có field này
company = client.read('res.company', [id], ['period_lock_date'])
✅ ĐÚNG — field mới
company = client.read('res.company', [id], ['fiscalyear_lock_date'])
✅ AN TOÀN — luôn try-except
try:
company = xmlrpc_search_read('res.company',
[('id', '=', company_id)], ['fiscalyear_lock_date'])
except Exception:
pass # field not available
Models VẪN CÓ company_id
Hầu hết transactional models vẫn có company_id:
account.move, account.move.linesale.order, purchase.orderaccount.journal, account.taxhr.payslip, hr.employeepos.session, mrp.productionPhát hiện khi
Xây dựng Accounting Health Check skill system — test trên staging với 3 companies (NOTE/HS/Fosllea).
Ảnh hưởng
account.account, product.category, product.template phải update.claude/skills/accounting-health/scripts/health_check.py
📚 Published from Company Knowledge Base — T08
Last updated:
Review by: 2026-06-10