我有Object类,我需要在这个类中浏览模型document.directory。我试过这个。
class node_database(object):
obj=openerp.registry(cr.dbname).get('document.directory')
print'obj',obj # it ptints document.directory
datas=obj.browse(cr,uid,ids)
print'datas',datas # Here nothing print
并尝试了这个:
osv_pool = pooler.get_pool(dbname)
dir_obj=osv_pool.get('document.directory')
搜索功能正常但浏览不是吗? 得到此错误:
2016-06-24 06:41:52,690 9427 ERROR dms1 openerp.addons.document_ftp.ftpserver: Traceback (most recent call last):
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/ftpserver.py", line 1806, in try_as_current_user
re=self.run_as_current_user(function, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/ftpserver.py", line 1779, in run_as_current_user
return function(*args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/abstracted_fs.py", line 509, in get_list_dir
listing = self.listdir(datacr)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document_ftp/ftpserver/abstracted_fs.py", line 377, in listdir
res = node.children(cr)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document/document.py", line 981, in children
res = self._child_get(cr, domain=domain) + self._file_get(cr)
File "/home/kabeer/odoo-8.0-20151229/openerp/addons/document/document.py", line 1022, in _child_get
print'cntobj_search_read',cntobj.search_read(cr, uid,[('id','=',1)],['name'],context=ctx)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 256, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/models.py", line 5186, in search_read
result = self.read(cr, uid, record_ids, fields, context=read_ctx)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 256, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/models.py", line 3144, in read
records = self.browse(cr, user, ids, context)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 256, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kabeer/odoo-8.0-20151229/openerp/models.py", line 5266, in browse
return self._browse(Environment(cr, uid, context or {}), ids)
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 740, in __new__
env, envs = None, cls.envs
File "/home/kabeer/odoo-8.0-20151229/openerp/tools/func.py", line 109, in __get__
return self.fget.__get__(None, owner)()
File "/home/kabeer/odoo-8.0-20151229/openerp/api.py", line 713, in envs
return cls._local.environments
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 71, in __getattr__
raise AttributeError(name)
AttributeError: environments
任何解决方案?
答案 0 :(得分:0)
for item in obj.search(cr, uid, []):
obj = self.browse(cr, uid, item)
print obj.name
答案 1 :(得分:0)
通过创建新游标解决了此问题。
new_cr = openerp.sql_db.db_connect(self.context.cr.dbname).cursor()
uid, context = self.context.uid, self.context.context
with api.Environment.manage():
self.env = api.Environment(new_cr, uid, context)
try:
datas=obj.browse(cr,uid,ids)
print'datas',datas # Here print
finally:
self.env.cr.close()