Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
2512 Tampilan
Jawaban Terbai

Hi, It is a environment object that Encapsulates cr, uid, context:


recs.env encapsulates cr, uid, context:

recs.env.cr     # shortcut: recs._cr
recs.env.uid     # shortcut: recs._uid
recs.env.context     # shortcut: recs._context


recs.env also provides helpers:

recs.env.user      # uid as a record
recs.env.ref('base.group_user')      # resolve xml id
recs.env['res.partner']    # access to new-API model


Switching environments:

rebrowse recs with different parameters

env2 = recs.env(cr2, uid2, context2)
recs2 = recs.with_env(env2)

special case: change/extend the context

recs2 = recs.with_context(context2)
recs2 = recs.with_context(lang='fr')    # kwargs extend current context


special case: change the uid

recs2 = recs.sudo(user)
recs2 = recs.sudo()          # uid = SUPERUSER_ID

Avatar
Buang
Jawaban Terbai

Hello Novizco,

It is a wrapper class that wraps 

 cr - current database cursor

 uid - current user id

 context - context dictionary

 

also it manages the pool of objects i.e. registry the models 

Earlier these attributes were having independent existance, but from v8 these attributes gets wrapped under "env". You can access them as follows :

self.env.cr

self.env.uid

self.env.context

which gives more object oriented approach.

Regards

Avatar
Buang