Odoo Help

Welcome!

This community 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.

4

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/14/14, 12:25 AM
Seen: 463 times
Last updated: 3/16/15, 8:10 AM