Odoo Help

4

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3712
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 7/14/14, 6:53 AM

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

2

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

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: 7/14/14, 12:25 AM
Seen: 582 times
Last updated: 3/16/15, 8:10 AM