Skip to content

Instantly share code, notes, and snippets.

@nseinlet
Created May 3, 2019 07:51
Show Gist options
  • Save nseinlet/01a6a764276063aeaea2983692f5d287 to your computer and use it in GitHub Desktop.
Save nseinlet/01a6a764276063aeaea2983692f5d287 to your computer and use it in GitHub Desktop.
read all odoo models
# coding: utf-8
import odoolib
from datetime import datetime, date
from dateutil.relativedelta import relativedelta
connection = odoolib.get_connection(hostname="localhost", database="odoo", login="admin", password="admin", port=8069)
ir_model = connection.get_model("ir.model")
model_ids = ir_model.search([])
for model_id in model_ids:
model_name = ir_model.read(model_id, ['model'])['model']
my_model = connection.get_model(model_name)
res = my_model.load_views(views=[(False, "list"), (False, "form"), (False, "search")])
print([n for n in res.get('fields_views').get('list').get('fields').keys()])
try:
t1 = datetime.now()
my_ids = my_model.search([])
if my_ids:
if len(my_ids) > 2000:
my_ids = my_ids[:2000]
my_model.read(my_ids)
t2 = datetime.now()
print("Done %s : %s (%s seconds)" % (model_name, len(my_ids), (t2-t1).seconds))
except Exception:
print("Model %s failed" % model_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment