This question has been flagged
1 Reply
9654 Views

Hi Guys ...

from what I understood should self.pool['whatever'].browse(cr, uid, SINGLEID)  return a dictonary object.

current_obj = self.pool['mymod.myclass'].browse(cr, uid, oid)

But

length = current_obj.len()

doesn't work and throws an error.

I want now to get the key and value pair of the _columns dictonary and tried:

for (key, value) in current_app_obj.items(): ... 

or

for key in current_app_obj.keys(): ... 
     value = getattr(current_app_obj, key)

and also

keys = current_app_obj.keys()
for key in keys:
       value = getattr(current_app_obj, key)

>>>  [...] raise except_osv('Object Error', 'Object %s doesn\'t exist' % str(obj))
except_osv: ('Object Error', "Object object.name doesn't exist")

Where is my error? Is the return value of browse really a dictonary? Why can't I use the standart methods?

Which libraries do I have to include?

Any hint is appreciated.

Avatar
Discard
Best Answer

Hello Peter,

I think you didn't understand standard methods, their use and their return type.

First thing is you should use `self.pool.get('your.object.name')`.

Browse method always returns browse object not dictionary.

If you pass single ID in browse method, it will return single browse record. Same way if you pass list of IDs, it will return list of browse records.

You can get values of any field from browse record using . (dot) operator.

If you want a dictionary, you should use read method which returns dictionary with fields name as a key and fields value in value of the dictionary.

You can refer following link for standard methods.

ORM Methods

Hope this will help you.

Avatar
Discard
Author

hi, Sudhir... current_obj = self.pool['mymod.myclass'].browse(cr, uid, oid) works just the same or even better as mentioned here: http://hypered.io/blog/2013-12-30-self-pool-get/ but your hint using read instead of browse made my day! THX... Thumb up!

Better you use self.pool.get() that is the better approach.