Odoo Help

3

How to send context from models.Model to osv.osv ?

By
Miftahussalam
on 5/16/15, 5:14 AM 1,264 views

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 ?

4
Temur
On 5/16/15, 6:06 AM

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

Miftahussalam
on 5/16/15, 9:26 AM

you're welcome

Temur
on 5/16/15, 9:37 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/16/15, 5:14 AM
Seen: 1264 times
Last updated: 6/7/17, 2:18 AM