Utilities to make better use of OdooRPC
This module offers functions to:
Instantiate common Odoo RPC libraries from a single .ini file (currently odooly and odoorpc supported);
Run DEEP read and search_read queries, retrieving data from multiple models at once, in an efficient manner and using parallel execution of RPCs;
The function to support deep queries can also be used as a building block to support GraphQL or GraphQL-like querying.
- Extend the utils package to support GraphQL queries;
- Write an odoorpc_fast class to speed-up RPC queries by using HTTP sessions and gzip encoding;
- Many, many potential functionalities... feel free to help writing and suggesting!
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)
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])
Sample odoorpc_utils.ini file:
[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
Sample queries.ini file
[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
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|odoorpc_utils-1.0.7-py3-none-any.whl (16.5 kB) Copy SHA256 hash SHA256||Wheel||py3|
|odoorpc-utils-1.0.7.tar.gz (6.6 kB) Copy SHA256 hash SHA256||Source||None|