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

I want to send context when call method in class osv.osv from models.Model (new api) like this :


In models.Model :

ctx = {'key' : 'value'}

self.picking_id.do_transfer(context=ctx)


In osv.osv :

@api.cr_uid_ids_context

def do_transfer(self, cr, uid, picking_ids, context=None):

print "context.get('key')================>>>>>>>>>>>>>>>>",context.get('key')

return True

And result from print is :

context.get('key')================>>>>>>>>>>>>>>>> None


Why the result is None ?

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

1. there is no difference between osv and Model as osv = Model,  osv is keept for backward compatibility 

2. in v8 there is function with_context() for such cases, use it:

self.picking_id.with_context(key='value').do_transfer() 
อวตาร
ละทิ้ง
ผู้เขียน

It works, thank you Temur

you're welcome

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 25
1445
0
ก.ค. 22
2497
3
ก.ย. 20
3160
Significance of context ? แก้ไขแล้ว
2
ธ.ค. 15
4754
0
มี.ค. 15
3489