Skip to main content

Odoo library for RPC

Project description

https://gitlab.com/katyukha/odoo-rpc-client/badges/master/pipeline.svg https://gitlab.com/katyukha/odoo-rpc-client/badges/master/coverage.svg https://img.shields.io/readthedocs/odoo-rpc-client.svg PyPI - Downloads

Canonical source

The canonical source of odoo-rpc-client is hosted on GitLab.

Overview

This is core part of OpenERP Proxy

This project is just RPC client for Odoo. This project provides interface similar to Odoo internal code to perform operations on Odoo objects hiding XML-RPC or JSON-RPC behind.

Features

  • Python 3.5+ support

  • You can call any public method on any OpenERP / Odoo object including: read, search, write, unlink and others

  • Have a lot of speed optimizations (caching, read only requested fields, read data for all records in current set (cache), by one RPC call, etc)

  • Desinged to take as more benefits of IPython autocomplete as posible

  • Provides browse_record like interface, allowing to browse related models too. Supports browse method. Also adds method search_records to simplify search-and-read operations.

  • Extension support. You can easily modify most of components of this lib creating Your own extensions and plugins. It is realy simple. See for examples in openerp_proxy/ext/ directory.

  • Plugin Support. Plugins are same as extensions, but aimed to implement additional logic. For example look at odoo_rpc_client/plugins and odoo_rpc_client/plugin.py

  • Support of JSON-RPC for version 8+ of Odoo

  • Support of using named parametrs in RPC method calls (server version 6.1 and higher).

  • Experimental integration with AnyField

  • Missed feature? fill and issue on GitHub or GitLab

Quick example

from odoo_rpc_client import Client

# assume that odoo server is listening localhost on standard 8069 port and
# have database 'my_db'.
client = Client('localhost', 'my_db', 'user', 'password')

# get current user
client.user
print(client.user.name)

# simple rpc calls
client.execute('res.partner', 'read', [client.user.partner_id.id])

# Model browsing
SaleOrder = client['sale.order']
s_orders = SaleOrder.search_records([])
for order in s_orders:
    print(order.name)
    for line in order.order_line:
        print("\t%s" % line.name)
    print("-" * 5)
    print()

Supported Odoo server versions

Tested with: - Odoo versions: 10.0, 11.0, 12.0, 13.0, 14.0 - Python versions: 2.7, 3.5, 3.6, 3.7, 3.8, 3.9

Install

This project is present on PyPI so it could be installed via PIP:

pip install odoo_rpc_client

Yodoo Cockpit - Manage your odoo infrastructure via odoo

Yodoo Cockpit - Manage your odoo infrastructure via odoo

Take a look at Yodoo Cockpit project, and discover the easiest way to manage your odoo installation. Just short notes about Yodoo Cockpit:

  • start new production-ready odoo instance in 1-2 minutes.

  • add custom addons to your odoo instances in 5-10 minutes.

  • out-of-the-box email configuration: just press button and add some records to your DNS, and get a working email

  • make your odoo instance available to external world (internet) in 30 seconds (just add single record in your DNS)

If you have any questions, then contact us at info@crnd.pro, so we could schedule online-demonstration.

Level up your service quality

Level up your service with our Helpdesk / Service Desk / ITSM solution.

Just test it at yodoo.systems: choose template you like, and start working.

Test all available features of Bureaucrat ITSM with this template.

Usage

Connect to server / database

The one diference betwen using as lib and using as shell is the way connection to database is created. When using as shell the primary object is session, which provides some interactivity. But when using as library in most cases there are no need for that interactivity, so connection should be created manualy, providing connection data from some other sources like config file or something else.

So here is a way to create connection

from odoo_rpc_client import Client
db = Client(host='my_host.int',
            dbname='my_db',
            user='my_db_user',
            pwd='my_password here')

And next all there same, no more differences betwen shell and lib usage.

General usage

For example lets try to find how many sale orders in ‘done’ state we have in our database. (Look above sections to get help on how to connect to Odoo database)

>>> sale_order_obj = db['sale.order']  # or You may use 'db.get_obj('sale.order')' if You like
>>>
>>> # Now lets search for sale orders:
>>> sale_order_obj.search([('state', '=', 'done')], count=True)
5

So we have 5 orders in done state. So let’s read them.

Default way to read data from Odoo is to search for required records with search method which return’s list of IDs of records, then read data using read method. Both methods mostly same as Odoo internal ones:

>>> sale_order_ids = sale_order_obj.search([('state', '=', 'done')])
>>> sale_order_datas = sale_order_obj.read(sale_order_ids, ['name'])  # Last argument is optional.
                                                                      # it describes list of fields to read
                                                                      # if it is not provided then all fields
                                                                      # will be read
>>> sale_order_datas[0]
{'id': 3,
 'name': 'SO0004'
}

As we see reading data in such way allows us to get list of dictionaries where each contain fields have been read

Another way to read data is to use search_records or read_lecords method. Each of these methods receives same aguments as search or read method respectively. But passing count argument for search\_records will cause error. Main difference betwen these methods in using Record class instead of dict for each record had been read. Record class provides some orm-like abilities for records, allowing for example access fields as attributes and provide mechanisms to lazily fetch related fields.

>>> sale_orders = sale_order_obj.search_records([('state', '=', 'done')])
>>> sale_orders[0]
R(sale.order, 9)[SO0011]
>>>
>>> # So we have list of Record objects. Let's check what they are
>>> so = sale_orders[0]
>>> so.id
9
>>> so.name
SO0011
>>> so.partner_id
R(res.partner, 9)[Better Corp]
>>>
>>> so.partner_id.name
Better Corp
>>> so.partner_id.active
True

Additional features

Plugins

In version 0.4 plugin system was completly refactored. At this version we start using extend_me library to build extensions and plugins easily.

Plugins are usual classes that provides functionality that should be available at db.plugins.* point, implementing logic not related to core system.


For more information see source code and documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odoo_rpc_client-1.2.0.tar.gz (74.9 kB view details)

Uploaded Source

Built Distribution

odoo_rpc_client-1.2.0-py2.py3-none-any.whl (74.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file odoo_rpc_client-1.2.0.tar.gz.

File metadata

  • Download URL: odoo_rpc_client-1.2.0.tar.gz
  • Upload date:
  • Size: 74.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for odoo_rpc_client-1.2.0.tar.gz
Algorithm Hash digest
SHA256 dee1076985277d9f952571fc3fbb1c1341dfa4582acd290fb6c6f9c7bf498cf1
MD5 3f2bcf1f789394dc432264f88957731b
BLAKE2b-256 3e0a30c716ff2fa94a999baa5ead1de0caaaa9c18937eafae4e0c1f4155f81b5

See more details on using hashes here.

File details

Details for the file odoo_rpc_client-1.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for odoo_rpc_client-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d7638f191596824381769ed3e76b0dff5035f84f8fd5ea180a94b36f613e557
MD5 862658115290409dc77e5703885f0612
BLAKE2b-256 7d9503450ce2f0022f7cce7f45f8ea62e0eacbfd9ad570f74587a0de13061193

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page