在odoo框架中编程的简单而强大的工具(f.e shell、独立应用程序中的模型参考、模型间通信的中介模式)
odoo_gatewa的Python项目详细描述
这个包实现了一些工具,帮助您使用 奥多模型的机械化。使用ODOO网关,您将能够
- 在shell中运行模型的方法。当你需要修理时有用 数据库数据或测试代码。
- 创建独立脚本,可以引用odoo模型并调用 他们的方法。
版本
0.0.1
技术
要正确使用奥多网关,您只需要 Odoo7或8个版本的库。
安装
您可以使用pip:
$ pip install odoo_gateway
外壳
可以使用以下命令启动外壳:
$ odoosh [params]
参数与openerp server的参数相同。您可以随时列出,只需键入:
$ odoosh --help
好吧,我们现在就开始吧!:
$ odoosh -c config_file.conf -d database1 In [1]:
很好! 奥多炮弹现在发射。以下对象已在命名空间中:
cr-psycopg光标的odoo包装:
In [2]: cr <openerp.sql_db.Cursor at 0x3450d50> In [3]: cr.execute("select id, name from sale_order limit 1") In [4]: cr.fetchall() [(600094, u'SALE-123456')]``
conn-psycopg与数据库的连接:
In [5]: conn <connection object at 0x3485f60; dsn: 'host=localhost port=5432 user=odoo password=xxxx dbname=database1', closed: 0> In [6]: conn.rollback()
rr-psycopg的光标
uid-odoo超级用户的id
conf-包含解析的odoo参数的openerp.tools.config.configmanager实例:
In [7]: conf <openerp.tools.config.configmanager at 0x210bbd0> In [8]: conf['db_name'] database1 In [9]: conf['db_host'] localhost
型号-odoo型号适配器列表。
In [10]: models.sale_order # get reference for model sale.order sale.order() In [11]: type(models.sale_order) openerp.api.sale.order In [12]: """Now we are free to apply API and user defined methods of model.""" In [13]: sale1 = models.sale_order.search([('name','=', 'sale-111111')]) In [14]: sale1.name sale-111111 In [15]: sale2 = models['sale.order'].search([('name','=', 'sale-111112')]) In [16]: sale2.name sale-111112
有两种方法可以参考odoo模型。
- You can use model’s name name.of.model and get reference with models[name.of.model]. See line 15 of example above.
- Or you can replace ‘.’ with ‘_’ and type models.name_of_model. The result will be the same as in previous point. See lines 10-14.
- session-odoo_gateway.session.session的实例
独立脚本
有些问题需要在openerp api之外使用openerpapi 服务器,在另一个独立进程中。例如,假设您 开一家商店。完成了吗?好的。有一个python应用程序。应用程序是 Messenger和使用队列系统。客户发送消息 他们描述他们想买什么样的产品。应用程序获取消息 从队列中,解析它们并在数据库中创建销售订单。
我相信这个应用不需要启动openerp server。不,先生!
您需要的只是odoo_gateway.session.session的实例,它是 使用ODOO服务器的命令参数启动。
from odoo_gateway import Session session = Session(['-c', 'config.conf', '-d', 'testdb'])
当您得到session对象时,您可以得到任何您可能梦寐以求的内容。
models = session.models cr = session.cr conn = session.conn uid = session.uid rr = session.rr conf = session.conf # The power is yours now def create_sale(**params): models.sale_order.create(**params) cr.commit()
许可证
bsd