Odoo Help


How to access to the ORM from outside properly ?

on 9/5/14, 5:10 AM 1,410 views

Hello !

I have to access to the ORM of openERP 7 from a python script.

I tried:

>>> import openerp

>>> pool = openerp.pooler.get_pool('test')

No handlers could be found for logger "openerp.modules.module"

>>> my_obj = pool.get('my_obj')

>>> type(my_obj)

<type 'NoneType'>

As you can see, I can't access to custom objects (e.g. tables) from outside. I've listed all the objects in the pool via pool.obj_list(), and it seems that the list is too short, even including official modules that are installed.

So, how can I access to all the objects that represents the tables of my database 'test' ?

Thanks !

PS: I can do stuff via XMLRPC instead, but I would like to use the ORM, because it's faster (already tested it).

EDIT: No one ?

Here's a more detailed example :

import openerp
import sys
import synconfig

DBNAME = "test"
uid = 1

cr = openerp.sql_db.db_connect(DBNAME).cursor()
pool = openerp.pooler.get_pool(DBNAME)

ir_model = pool['ir.model']
data = ir_model.search(cr, uid, [])
print 'data from ir.model: %d' % len(data)

my_object = pool['my.object']
data = my_object.search(cr, uid, [])
print 'data from my.object: %d' % len(data)

Output :

data from ir.model: 334
Traceback (most recent call last):
  File "./orm_outside.py", line 20, in <module>
    my_object = pool['my.object']
  File "/home/openerp/server/openerp/modules/registry.py", line 102, in __getitem__
    return self.models[model_name]
KeyError: 'my.object'



| 5 3 6
Jakarta, Indonesia
On 9/8/14, 7:17 AM

AFAIK, I don't think you can use ORM outside OpenERP without having to recreate the whole framework first.

What are you trying to achieve by accessing the ORM outside the framework?  Can it be performed within the framework instead?

Hi ! I have a socket server that will receive asynchronous responses from a previous request made inside the ORM. I can handle the asynchronous response with XMLRPC, but the ORM beeing faster, that's why I would like to use it. And also, I'm curious to know why I can access the basic modules, and not the others. Oh, and the request being asynchronous, it cannot, of course, be handled inside the ORM.

on 9/9/14, 3:10 AM

There are facilities such as Automated Actions and Scheduled Actions that can be used to perform asynchronous processes. As I mentioned, you need to recreate the supporting structure of the ORM first before using the ORM outside. OpenERP created a special namespace which is used for importing stuff within OpenERP. If you check the openerp/osv/orm.py file, on the top you'll find lines such as import openerp.netsvc, etc. So to use orm.py file, you need to have those files as well located at the path as specified (and so on, you need to trace the other imports that are needed by those imported files respectively). I haven't tried this, but maybe installing OpenERP using the binary package might help as if you install OpenERP using binary package, it will be stored within the PYTHON PATH.

on 9/9/14, 3:58 AM

The python path isn't a problem, because I can include my addons folders in sys.path, then import a custom addon. However, that does not solve the problem, the pool does not contain the custom addon's objects.

on 9/10/14, 3:17 AM

PY, sys.path is different from PYTHON PATH.

on 9/11/14, 2:14 AM

I think I understand a little better. I think it's the instanciation of the pool that the addons must be added, but how, I will need to find out. (On a side note, I already now how to fix my code with xmlrpclib, so from this point, this question is just curiosity ^^)

on 9/11/14, 3:36 AM

Congratulation PY. It would be great if you can share what you have learned with all of us. And yes, the instanciation of the objects in addons and especially base must be proper to create a proper OpenERP environment.

on 9/11/14, 3:46 AM

Pfff, this is a mess... I've been reading the code for more than an hour now, and I think I will pass for today ^^ I've learned a lot, but not enough. However, I will accept your answer, since it's not so easy to do it. People (including me) would be better served with xmlrpc. Thanks anyway !

on 9/11/14, 4:52 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 9/5/14, 5:10 AM
Seen: 1410 times
Last updated: 3/16/15, 8:10 AM