odoorpc.env¶
Supply the Environment class to manage records more efficiently.
- 
class odoorpc.env.Environment(odoo, db, uid, context)¶
- 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}) - 
__contains__(model)¶
- Check if the given model exists on the server. - >>> 'res.partner' in odoo.env True - Returns: - True or False 
 - 
__getitem__(model)¶
- Return the model class corresponding to model. - >>> Partner = odoo.env['res.partner'] >>> Partner Model('res.partner') - Returns: - a - odoorpc.models.Modelclass
 - 
context¶
- The context of the user connected. - >>> odoo.env.context {'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1} 
 - 
db¶
- The database currently used. - >>> odoo.env.db 'db_name' 
 - 
lang¶
- Return the current language code. - >>> odoo.env.lang 'en_US' 
 - 
ref(xml_id)¶
- Return the record corresponding to the given xml_id (also called external ID). Raise an - RPCErrorif no record is found.- >>> odoo.env.ref('base.lang_en') Recordset('res.lang', [1]) - Returns: - a - odoorpc.models.Modelinstance (recordset)- Raise: - odoorpc.error.RPCError
 - 
registry¶
- 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 {} 
 - 
uid¶
- The user ID currently logged. - >>> odoo.env.uid 1 
 - 
user¶
- Return the current user (as a record). - >>> user = odoo.env.user >>> user Recordset('res.users', [1]) >>> user.name 'Administrator' - Returns: - a - odoorpc.models.Modelinstance- Raise: - odoorpc.error.RPCError
 
- 
