更好地利用odorpc的实用程序

odoorpc-utils的Python项目详细描述


概述

本模块提供以下功能:

  1. 从单个.ini文件实例化通用的odoo rpc库(当前支持odooly和odoopc);

  2. 运行deep读取和搜索读取查询,从多个 以高效的方式立即建模并使用rpcs的并行执行;

  3. 支持deep查询的函数也可以用作构建 块以支持graphql或类似graphql的查询。

待办事项:

  • 扩展utils包以支持graphql查询;
  • 编写一个odorpc_fast类,通过使用http会话和gzip编码来加速rpc查询;
  • 很多,很多潜在的功能…请随时帮助写作和建议!

示例1:

from odoorpc_utils import FastDeepQueries, OdooInstantiator

# read from file odoorpc_utils.ini, odoorpc-utils.ini or odooly.ini
# If you prefer you can skip this and instantiate odoorpc the old way.
odoo = OdooInstantiator.odoorpc_from_config_file('production')

# pass an instance of logged-in odoorpc here (odooly not supported at the moment)
fdq = FastDeepQueries(odoo)

# Let's get the id of 100 sales orders...
ids = fdq.query_fast(model_name='sale.order', limit=100)

# The fields you want to retrieve are specified in this easy to understand syntax...
fields = ['number,date_confirmed,order_total',
          'partner_id.name,address,zip,city,state,tax_number',
          'sale_order_line_ids.quantity, unit_price, total_price',
          'sale_order_line_ids.product_id.name,reference']

# ...which is then parsed, relations are retrieved and a more complex structure of dicts is built
fields_deep = fdq.build_fields_deep_structure(model_name='sale.order', fields_deep=fields)

# Now let's make a deep query for 100 sales order and see how fast it is 
# Nope, it will not be blazing fast, it will actually be quite slow, but MUCH faster 
# than what you usually get from odoorpc...
res = fdq.query_deep(fields_deep, ids=ids, n_threads=8)

# Done!

# RPC is slow... each query takes ~1 second, larger queries can take much longer. Running them in
# parallel speeds things up significantly (but it is still RPC)

print(res)

例2:

from odoorpc_utils import FastDeepQueries, OdooInstantiator

odoo = OdooInstantiator.odoorpc_from_config_file('production')    
fdq = FastDeepQueries(odoo)

# We can also run queries defined on a queries.ini file
res = fdq.named_query('picking list report', ids=[order_id])

示例odorpc\u utils.ini文件:

[DEFAULT]
port = 443
username = user
password = pass

# Odooly-specific
scheme = https
protocol = jsonrpc

#OdooRPC-specific
timeout = 3600
# if **protocol_odoorpc** is missing, the param protocol will be
# used with odoorpc instead. But Odooly and OdooRPC do not support the same
# syntax for the protocol string, hence why an odoorpc-specific option exists
protocol_odoorpc = jsonrpc+ssl

[production]
host = www.my.tld
database = my_production_database

[testing]
host = testing.my.tld
database = testing_database

示例querys.ini文件

[DEFAULT]
# acceptable values are all parameters of the query_deep function
# with the exception of fields_deep that MUST be provided by means of the
# fields *model name* and *fields*.
n_threads = 8

# format_for__id_fields
# 1 for [id, 'Name'] - Standard OdooRPC.
# 2 for [id] - useful to have both _id and _ids fields on list of ids, but all
#              _id fields have one id only, so the list is not necessary
#              and also the create/write calls do not accept a list with one id.
# 3 for the id as an int - default. Best if you plan to later use the create/write calls
format_for__id_fields = 3

[picking list report]
model name = sale.order
fields = number,date_confirmed,order_total
fields = partner_id.name,address,zip,city,state,tax_number
fields = sale_order_line_ids.quantity, unit_price, total_price
fields = sale_order_line_ids.product_id.name,reference

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么单元测试中的“验证”在不同实例的情况下不返回“不同参数”错误?   java如何从具有相同类名的div中选择元素(Selenium)   Java制作纸牌游戏,有关于类的问题吗   bluej在Java中使用变异器和访问器设置颜色和圆半径   java准确定位异常错误的最佳方法是什么?   使用多个监视器时的java设置对话框位置   java如何在不使用JavascriptExecutor的情况下在网页中向下/向上滚动   java在for循环中将大小设置为n   java为什么akka需要不可变的消息   java LdapInvalidDnException:意外标记:   java如果字符串的第一个字母不是一个,如何大写?   使用htmlunit的java html内容提取   java从CDI托管bean获取方法的注释   java有办法在运行时检查post请求参数的大小吗   java我可以将实体注入托管Bean并直接持久化吗?