如何在 python 控制台中 运行 Odoo ORM 方法?
How to run Odoo ORM methods in the python console?
我想在 python 控制台中使用 ORM 方法,例如 browse
或 search
。
$pwd
/opt/odoo/
$python
>>> import openerp
>>> product_obj = pool.get('product.product)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pool' is not defined
我怎样才能做到这一点?
在第 9 版中,您可以使用 odoo.py shell -d <database>
启动 odoo shell,感谢 this commit
在版本 8 中,该功能不是内置的,但您可以使用 this script, this module, or OERPLib
Pool需要连接数据库,所以需要先实例化一个Pool,例如:
pool = openerp.modules.registry.RegistryManager.get("test")
这应该 return 一个连接到 'test' 数据库的池
我想在 python 控制台中使用 ORM 方法,例如 browse
或 search
。
$pwd
/opt/odoo/
$python
>>> import openerp
>>> product_obj = pool.get('product.product)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pool' is not defined
我怎样才能做到这一点?
在第 9 版中,您可以使用 odoo.py shell -d <database>
启动 odoo shell,感谢 this commit
在版本 8 中,该功能不是内置的,但您可以使用 this script, this module, or OERPLib
Pool需要连接数据库,所以需要先实例化一个Pool,例如:
pool = openerp.modules.registry.RegistryManager.get("test")
这应该 return 一个连接到 'test' 数据库的池