How to retrieve complete model schema via XML-RPC for documentation
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
Hi,
To retrieve a complete model schema from Odoo via XML-RPC, you can use the ir.model and ir.model.fields models. First, authenticate with Odoo using XML-RPC and set up the models proxy. You can then fetch a list of all models with search_read on ir.model to get both the technical and human-readable names.
For each model, you can query ir.model.fields to get the fields’ details, including name, label, type (ttype), relation (for relational fields), and required or readonly status. This allows you to generate a full schema for a model, showing all fields and their properties.
To document all models, you can loop through the list of models and fetch their fields in the same way. System models can be filtered out if not needed, and the schema can be exported to CSV or Markdown for easy reference. This approach provides a comprehensive view of all models and fields in the Odoo database.
1. Connect to Odoo via XML-RPC
import xmlrpc.client
url = "https://your-odoo.com"
db = "your_db"
username = "your_user"
password = "your_password"
# Authenticate
common = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/common")
uid = common.authenticate(db, username, password, {})
# Set up models proxy
models = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/object")
2. Get a list of all models
models_list = models.execute_kw(db, uid, password,
'ir.model', 'search_read',
[[]], # empty domain = all models
{'fields': ['model', 'name']}
)
for m in models_list:
print(m['model'], m['name'])
3. Retrieve all fields for a model
model_name = 'res.partner' # example model
fields_info = models.execute_kw(db, uid, password,
'ir.model.fields', 'search_read',
[[('model', '=', model_name)]],
{'fields': ['name', 'field_description', 'ttype', 'relation', 'required', 'readonly']}
)
for f in fields_info:
print(f)
-Some system models are technical and may not be needed for documentation (ir.actions.*, ir.model, etc.). You can filter them out.
-ttype indicates the type (char, many2one, one2many, float, etc.).
-relation is the related model for relational fields.
Hope it helps
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
3
thg 7 25
|
3574 | ||
|
3
thg 7 25
|
2458 | ||
|
3
thg 5 25
|
4240 | ||
|
1
thg 10 24
|
2601 | ||
|
1
thg 4 24
|
2709 |