"" An environment wraps data for ORM records: -: attr: ' Cr ', the current database cursor; -: attr: ' uid ', the current user ID; -: attr: ' context ', the current context dictionary. It also provides access to the registry, a cache for records, and a data structure to manage Recomputations. ""
The Environment class provides encapsulation of an ORM object, provides access to the registration class, caches the Recordset, and manages the data structure of the recalculation.
For classes that inherit the model, the environment can be manipulated directly through self.env.
Property list:
1.user: Returns the current user
Self.env.user
2.lang: Returns the current language code
Self.env.lang
3.in_draft: Returns whether in draft mode
Self.env.in_draft
4.in_onchange: Returns whether in ' onchange ' draft mode
Self.env.in_onchange
There are also attributes such as Cr,registery,cache,prefetch,computed,dirty,todo,mode,all
Application notes:
1. Use Env[model] to get the class object:
self.env[' Ir.model '].search ([' State ', '! = ', ' manual ')])
2. Execute SQL statements using CR:
Self.env.cr.execute (query, (value,))
Odoo 8.0 New API's environment