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 read fealds in new API

By
Alec Mouti
on 8/14/15, 12:07 PM 1,360 views

Learning Python and trying to understand the new odoo API has been a challenge to me.

how to I convert this method to new API? this will help me a lot in my attempt to grasp new API concept

 

def name_get(self, cr, uid, ids, context={}):

        if not len(ids):

                  return []

       reads = self.read(cr, uid, ids, ['name', 'lastname'], context)

       res = []

       for record in reads:

                 name = record['name']

                 if record['lastname']:

                        name = record['lastname'] + ', '+name

                res.append((record['id'], name))

                return res


the method read name and lastname  from res.partner

and append Id value to the name as return.

0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/14/15, 12:38 PM

To read a field you can learn from this example:

var =1

obj = self.pool.get('res.partner')

obj_ids = obj.search(cr, uid, [('id', '=', var)])

res = obj.read(cr, uid, obj_ids, ['name','id'], context)

Or You can use Environment.

The Environment stores various contextual data used by the ORM: the database cursor (for database queries), the current user (for access rights checking) and the current context (storing arbitrary metadata). The environment also stores caches.

Friend, Take a look to the official documentation of ODOO.

https://www.odoo.com/documentation/8.0/reference/orm.html

Regards


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: 8/14/15, 12:07 PM
Seen: 1360 times
Last updated: 8/14/15, 12:38 PM