콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
11126 화면

Hello Everyone,

In odoo , new coding standard we can have two context if we use api.

1) cr,uid, context = self.env.args,

2) self._context

We can get context two way, but value of both convext is different.

What is the different between these two context?

Thanks!

Regards,

Anil.    


아바타
취소

Can you post please what kind of differences you've spotted? Examples?

작성자

_context is frozon dictionary cannot update, like we were able to update till v7, some of the information are different for both context in same method.

작성자 베스트 답변

Hi Everyone,

When we extract both context which is implicity passed in any method having same information.

Like:

cr, uid, context = self.env.args
or

self._context

Both having same information even if you have passed any external key from client side, you will get the same in both context.

But first different I have suspected is,

while I was using context with recursion:

I was trying to passed the external key to context which is frozon dictionary or self._context to access info inside the same method.

by using with_context we can directly pass the our key to frozone dictionory or self._context

So, it was not showing the key in the next call of same method (Recursion).

Here is the syntax to pass any key using with_context

eg:

@api.multi
def custom_method(self)
#code here..
print "_context",self._context #so here i was not able to get the external key in next call.
if condition:
return True
self.with_context(key=value).custom_method() #recusrion

I found solution for it which works for me. Here is the sample example.

from openerp.tools import misc

@api.multi
def custom_method(self):
cr, uid, context = self.env.args

print "Context ::::",context
if condition:
return True
 
context = dict(context)
context.update({key:value})
self.env.args = cr, uid, misc.frozendict(context)
self.custom_method()

This is how I passed external key and got it, in the very next call of that function which was called within function.

Correct me if I am wrong!

If i will come up with more differences will update here.

Regards,

Anil.


아바타
취소
관련 게시물 답글 화면 활동
1
2월 25
639
0
3월 24
1290
0
1월 24
4144
2
1월 19
21365
1
12월 17
5849