-
-
Save iledarn/eec69246ad6442b70773b40b02612352 to your computer and use it in GitHub Desktop.
Revisions
-
dreispt created this gist
Nov 19, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ """ Setup: Assuming Odoo 8.0 sources at ~/odoo: $ cp odoo-sh.py ~/odoo $ cd ~/odoo $ python -i odoo-sh.py Usage example: >>> env = connect('my-db-name') >>> Users = env['res.users'] >>> Users.search() >>> Users.browse(1).name u'Administrator' """ from __future__ import print_function from openerp.modules.registry import RegistryManager from openerp.api import Environment def connect(dbname='trunk', uid=1, context=None): r = RegistryManager.get(dbname) cr = r.cursor() Environment.reset() env = Environment(cr, uid, context or {}) print('Connected to %s with user %s %s' % (dbname, env.uid, env.user.name)) return env if __name__ == '__main__': print(__doc__)