Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
146 Widoki

How to retrieve complete model schema via XML-RPC for documentation

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Prisha, retrieving the complete model schema via XML-RPC for documentation is possible, but it requires a specific approach.



  First, connect to Odoo via XML-RPC.

  Then, use the model.fields_get method to retrieve the field definitions for a specific model. This method returns a dictionary containing detailed information about each field, including its type, help text, and other attributes.

  To get all models, you might need to query the ir.model model to list all available models and then iterate through them, calling model.fields_get for each one.

  Finally, consolidate the data retrieved from each model into a structured format suitable for your documentation needs.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Prisha,
You can explore this Odoo 18 official documentation: https://www.odoo.com/documentation/18.0/developer/reference/external_api.html

Feel free to write us on: lakhan@codespheretech.in

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
lip 25
3540
3
lip 25
2451
3
maj 25
4227
1
paź 24
2583
1
kwi 24
2693