Supply the Environment class to manage records more efficiently.
An environment wraps data like the user ID, context or current database name, and provides an access to data model proxies.
>>> import odoorpc
>>> odoo = odoorpc.ODOO('localhost')
>>> odoo.login('db_name', 'admin', 'password')
>>> odoo.env
Environment(db='db_name', uid=1, context={'lang': 'fr_FR', 'tz': 'Europe/Brussels', 'uid': 1})
Return the model class corresponding to model.
>>> Partner = odoo.env['res.partner']
>>> Partner
Model('res.partner')
Returns: | a odoorpc.models.Model class |
---|
The context of the user connected.
>>> odoo.env.context
{'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1}
The database currently used.
>>> odoo.env.db
'db_name'
Return the current language code.
>>> odoo.env.lang
'en_US'
Return the record corresponding to the given xml_id (also called external ID). Raise an RPCError if no record is found.
>>> odoo.env.ref('base.lang_en')
Recordset('res.lang', [1])
Returns: | a odoorpc.models.Model instance (recordset) |
---|---|
Raise: | odoorpc.error.RPCError |
The data model registry. It is a mapping between a model name and its corresponding proxy used to generate records. As soon as a model is needed the proxy is added to the registry. This way the model proxy is ready for a further use (avoiding costly RPC queries when browsing records through relations).
>>> odoo.env.registry
{}
>>> odoo.env.user.company_id.name # 'res.users' and 'res.company' Model proxies will be fetched
'YourCompany'
>>> from pprint import pprint
>>> pprint(odoo.env.registry)
{'res.company': Model('res.company'), 'res.users': Model('res.users')}
If you need to regenerate the model proxy, simply delete it from the registry:
>>> del odoo.env.registry['res.company']
To delete all model proxies:
>>> odoo.env.registry.clear()
>>> odoo.env.registry
{}
The user ID currently logged.
>>> odoo.env.uid
1
Return the current user (as a record).
>>> user = odoo.env.user
>>> user
Recordset('res.users', [1])
>>> user.name
'Administrator'
Returns: | a odoorpc.models.Model instance |
---|---|
Raise: | odoorpc.error.RPCError |