تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
47505 أدوات العرض

hello I try to add new values in the context with the new api but after many try we did'nt sucess.

What we have try :

self.with_context(get_sizes=True)
print self.env.context
self.with_context({'get_sizes': True, 'free_ref': free_ref}) 
self.with_context().create(get_sizes=True)
الصورة الرمزية
إهمال

you can use

self.with_context(key='value').do_something

for old version 

self._context.update( { 'key': 'val' } ) 

or  

self.env.context.update( { 'key': 'val' } )

that will add values in context 


أفضل إجابة

Try this:

 self = self.with_context(get_sizes=True)
print self.env.context

or

self.with_context(get_sizes=True).create()

الصورة الرمزية
إهمال
الكاتب

This works ! self = self.with_context(get_sizes=True) Thank you very much !

أفضل إجابة

@Mohit, that's not true.  As of Odoo 11 anyway, a context is a Python frozendict, which cannot be updated.

And even if you were to do something like:

 self.env.context = dict(self.env.context)
self.env.context.update({'key': 'val'})

the effect would only affect the context associated with recordset passed to the method where this code appears.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 17
5790
3
أبريل 17
24400
1
يناير 25
1356
0
يوليو 22
2442
1
نوفمبر 21
6086