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
- Bogføring
- Lager
- PoS
- Project
- MRP
Dette spørgsmål er blevet anmeldt
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Tilmeld digRelated Posts | Besvarelser | Visninger | Aktivitet | |
---|---|---|---|---|
|
3
jul. 25
|
3574 | ||
|
3
jul. 25
|
2458 | ||
|
3
maj 25
|
4240 | ||
|
1
okt. 24
|
2601 | ||
|
1
apr. 24
|
2709 |