Odoo Help

Welcome!

This community 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.

0

Odoo 8 -Browse a model in Object Class

By
Kabeer
on 6/22/16, 5:56 AM 449 views

I have Object class and i need to browse the model document.directory in this class. I tried this.


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

and also tried this:

  osv_pool = pooler.get_pool(dbname)
  dir_obj=osv_pool.get('document.directory')

Thnks Ajeng for your reply. I tried this :

dir_obj = pooler.get_pool(dbname).get('document.directory')

document_id=dir_obj.search(cr,uid,[('id','=',ids[0])])

print'document_id',document_id #It prints correct value

document_data=dir_obj.browse(cr,uid,document_id) #not get into browse function

print'document_data',document_data #not print

Kabeer
on 6/23/16, 6:48 AM

Getting this Error:

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

Kabeer
on 6/24/16, 2:45 AM
0
Ajeng Shilvie
On 6/23/16, 5:48 AM

Before u browse the other model, u have to make sure if there is some parameter that have to be search before u browse the model. such as :

document_search = self.pool.get('document.directory').search(cr,uid,[('field_name','=',condition)])

#after that u can browse like this
document_browse = self.pool.get('document.directory').browse(cr,uid,document_search)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/22/16, 5:56 AM
Seen: 449 times
Last updated: 6/23/16, 5:48 AM