Odoo Help

2

what is self.env?

By
Deepak Krishna
on 10/16/15, 12:09 AM 9,752 views

Why self.env is used for searching or browsing? How it works ?

Can any one tell me why it is used and its working .


6

Baiju KS

--Baiju KS--
3249
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju KS
On 10/16/15, 1:40 AM

Hi,

env(Environment) in new API is to provide an encapsulation around cursor, user_id, model, and context, Recordset and caches.

It evades the use of infamous function signature def afun(self, cr, uid, ids, context=None): and in new API its def afun(self):

And if you want to call ORM method directly from an object you can use self.env['obj'].method   instead of self.method

For more about env:-  Link

Hope this helps.


Thank you for the reply.And what i understood is that, the self.env environment reference allows us to access any other model. For example, self.env['res.partner'] returns a reference to the Partners model. We can then use search() or browse() on it to generate recordsets.

Deepak Krishna
on 10/16/15, 3:04 AM
6

Akhil P Sivan

--Akhil P Sivan--
4045
| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/16/15, 1:31 AM

self.env['model.name'] is used instead of self.pool.get('model.name') in the old api, to access the recordset of a particular model. In the old api, with search and browse you had pass cr, uid, context seperately, whereas with self.env it is implicit.

An environment wraps data for ORM records:

  • 'cr', the current database cursor.

  • 'uid', the current user id.

  • 'context', the current context dictionary.

You may check this link:

http://www.mindissoftware.com/2014/11/06/Understand-Odoo-Environment/ 

http://odoo-new-api-guide-line.readthedocs.org/en/latest/environment.html#environment 

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

2 follower(s)

Stats

Asked: 10/16/15, 12:09 AM
Seen: 9752 times
Last updated: 6/26/17, 2:12 PM