Odoo Environment | Odoo Self | self.env in Odoo || Odoo Environment Variables
Odoo Mates Odoo Mates
36.2K subscribers
11,572 views
203

 Published On Premiered Apr 20, 2022

What is self in odoo. What is a record set in odoo. How to traverse recordset in Odoo. Odoo environment variables. How to initialize odoo environment. Environmental variables in Odoo. How to alter odoo environment. What is odoo self.env . User object in odoo environment. Context in Odoo. Get user language in odoo python. Get current user id in odoo python. Get current company in odoo python. Odoo database cursor.

Need the playground module ? https://apps.odoo.com/apps/modules/15...
Feel free to buy from above link which will be a great support for us !!! If you cant buy, no issues, ping us in email: [email protected]

Available variables
- self: Current Object
- self.env: Odoo Environment on which the action is triggered
- self.env.user: Return the current user (as an instance)
- self.env.is_system: Return whether the current user has group "Settings", or is in superuser mode.
- self.env.is_admin: Return whether the current user has group "Access Rights", or is in superuser mode.
- self.env.is_superuser: Return whether the environment is in superuser mode.
- self.env.company: Return the current company (as an instance)
- self.env.companies: Return a recordset of the enabled companies by the user
- self.env.lang: Return the current language code
- self.env.cr: Cursor
- self.env.context: Context

The Environment stores various contextual data used by the ORM: the database cursor (for database queries), the current user (for access rights checking) and the current context (storing arbitrary metadata). The environment also stores caches.

All recordsets have an environment, which is immutable, can be accessed using env and gives access to:

the current user (user)

the cursor (cr)

the superuser flag (su)

or the context (context)

records.env
Environment object
records.env.user
res.user(3)

records.env.cr
Cursor object ...)
When creating a recordset from an other recordset, the environment is inherited. The environment can be used to get an empty recordset in an other model, and query that model:

self.env['res.partner']
res.partner()
self.env['res.partner'].search([['is_company', '=', True], ['customer', '=', True]])
res.partner(7, 18, 12, 14, 17, 19, 8, 31, 26, 16, 13, 20, 30, 22, 29, 15, 23, 28, 74)
Environment.ref(xml_id, raise_if_not_found=True)[source]
Return the record corresponding to the given xml_id.

Environment.lang
Return the current language code.

Return type
str

Environment.user
Return the current user (as an instance).

Returns
current user - sudoed

Return type
res_users

Environment.company
Return the current company (as an instance).

If not specified in the context (allowed_company_ids), fallback on current user main company.

Raises
AccessError – invalid or unauthorized allowed_company_ids context key content.

Returns
current company (default=`self.user.company_id`), with the current environment

Return type
res.company

Warning

No sanity checks applied in sudo mode ! When in sudo mode, a user can access any company, even if not in his allowed companies.

This allows to trigger inter-company modifications, even if the current user doesn’t have access to the targeted company.

Environment.companies
Return a recordset of the enabled companies by the user.

If not specified in the context(allowed_company_ids), fallback on current user companies.

Raises
AccessError – invalid or unauthorized allowed_company_ids context key content.

Returns
current companies (default=`self.user.company_ids`), with the current environment

Return type
res.company

Warning

No sanity checks applied in sudo mode ! When in sudo mode, a user can access any company, even if not in his allowed companies.

This allows to trigger inter-company modifications, even if the current user doesn’t have access to the targeted company.
Odoo 15 Playlist:    • How To Configure Odoo15 With Pycharm ...  

Website: https://www.odoomates.tech/
Instgram:   / odoomates  
Github: https://github.com/odoomates
Email : [email protected]
Facebook:   / odoomate  
Twitter:   / odoomates  
Support Us in Ko Fi : https://ko-fi.com/odoomates

show more

Share/Embed