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

How to get the Keys of a returned browse_record object?

By
Peter Nietz
on 9/5/14, 8:49 AM 1,475 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.

2

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 9/5/14, 1:50 PM

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.

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!

Peter Nietz
on 9/9/14, 9:16 AM

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

Sudhir Arya (SA)
on 9/9/14, 12:54 PM

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

0 follower(s)

Stats

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