odoorpc.rpc

This module provides Connector classes to communicate with an Odoo server with the JSON-RPC protocol or through simple HTTP requests.

Web controllers of Odoo expose two kinds of methods: json and http. These methods can be accessed from the connectors of this module.

class odoorpc.rpc.Connector(host, port=8069, timeout=120, version=None)

Connector base class defining the interface used to interact with a server.

property ssl

Return True if SSL is activated.

property timeout

Return the timeout.

class odoorpc.rpc.ConnectorJSONRPC(host, port=8069, timeout=120, version=None, deserialize=True, opener=None)

Connector class using the JSON-RPC protocol.

>>> from odoorpc import rpc
>>> cnt = rpc.ConnectorJSONRPC('localhost', port=8069)

Open a user session:

>>> cnt.proxy_json.web.session.authenticate(db='db_name', login='admin', password='password')
{'id': 51373612,
 'jsonrpc': '2.0',
 'result': {'company_id': 1,
            'currencies': {'1': {'digits': [69, 2],
                                 'position': 'after',
                                 'symbol': '€'},
                           '3': {'digits': [69, 2],
                                 'position': 'before',
                                 'symbol': '$'}},
            'db': 'db_name',
            'is_admin': True,
            'is_system': True,
            'name': 'Mitchell Admin',
            'partner_display_name': 'YourCompany, Mitchell Admin',
            'partner_id': 3,
            'server_version': '12.0',
            'server_version_info': [12, 0, 0, 'final', 0, ''],
            'session_id': '6dd7a34f16c1c67b38bfec413cca4962d5c01d53',
            'show_effect': True,
            'uid': 2,
            'user_companies': False,
            'user_context': {'lang': 'en_US',
                             'tz': 'Europe/Brussels',
                             'uid': 2},
            'username': 'admin',
            'web.base.url': 'http://localhost:8069',
            'web_tours': []}}

Read data of a partner:

>>> cnt.proxy_json.web.dataset.call(model='res.partner', method='read', args=[[1]])
{'jsonrpc': '2.0', 'id': 454236230,
 'result': [{'id': 1, 'comment': False, 'ean13': False, 'property_account_position': False, ...}]}

You can send requests this way too:

>>> cnt.proxy_json['/web/dataset/call'](model='res.partner', method='read', args=[[1]])
{'jsonrpc': '2.0', 'id': 328686288,
 'result': [{'id': 1, 'comment': False, 'ean13': False, 'property_account_position': False, ...}]}

Or like this:

>>> cnt.proxy_json['web']['dataset']['call'](model='res.partner', method='read', args=[[1]])
{'jsonrpc': '2.0', 'id': 102320639,
 'result': [{'id': 1, 'comment': False, 'ean13': False, 'property_account_position': False, ...}]}
property proxy_http

Return the HTTP proxy.

property proxy_json

Return the JSON proxy.

property timeout

Return the timeout.

class odoorpc.rpc.ConnectorJSONRPCSSL(host, port=8069, timeout=120, version=None, deserialize=True, opener=None)

Connector class using the JSON-RPC protocol over SSL.

>>> from odoorpc import rpc
>>> cnt = rpc.ConnectorJSONRPCSSL('localhost', port=8069)
property ssl

Return True if SSL is activated.