Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
10047 มุมมอง

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ส.ค. 25
1
0
ส.ค. 25
1016
1
ก.ค. 25
882
0
มิ.ย. 25
801
1
พ.ค. 25
1456