Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5555 Lượt xem

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 ?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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() 
Ảnh đại diện
Huỷ bỏ
Tác giả

It works, thank you Temur

you're welcome

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 25
1453
0
thg 7 22
2501
3
thg 9 20
3164
2
thg 12 15
4758
0
thg 3 15
3492