问题
I need to get all objects from a class and iterate through them. I tried this, but without any results:
def my_method(self, cr, uid, ids, context=None):
pool_obj = pooler.get_pool(cr.dbname)
my_objects=pool_obj.get('project.myobject')
#here i'll iterate through them...
How can I get in 'my_objects' variable all objects of class 'project.myobject'?
回答1:
You have to search with empty parameters to get all the ids of existing objects, like:
myobj = pool.get('project.myobject')
ids = myobj.search(cr, uid, [])
Then you can browse or read them passing an id or the list of ids.
回答2:
It seems you forget to import pooler.
from openerp import pooler
May it will help you.
来源:https://stackoverflow.com/questions/16101719/how-to-get-in-openerp-all-objects-from-a-class