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

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)
Ảnh đại diện
Huỷ bỏ

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 


Câu trả lời hay nhất

Try this:

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

or

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

@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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 17
5790
3
thg 4 17
24400
1
thg 1 25
1356
0
thg 7 22
2439
1
thg 11 21
6086