Created
May 3, 2019 07:51
-
-
Save nseinlet/01a6a764276063aeaea2983692f5d287 to your computer and use it in GitHub Desktop.
read all odoo models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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