Odoorpc Documentation: Release 0.6.2
Odoorpc Documentation: Release 0.6.2
Odoorpc Documentation: Release 0.6.2
Release 0.6.2
Sébastien Alix
1 Introduction 1
2 Quick start 3
3 Contents 5
3.1 Download and install instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.1 Python Package Index (PyPI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.2 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.3 Run tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.1 Create a new database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.2 Login to your new database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.3 Execute RPC queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.4 Browse records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.5 Call methods from a Model or from records . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.6 Update data through records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.7 Download reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.8 Save your credentials (session) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Frequently Asked Questions (FAQ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3.1 Why OdooRPC? And why migrate from OERPLib to OdooRPC? . . . . . . . . . . . . . . 14
3.3.2 Connect to an Odoo Online (SaaS) instance . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3.3 Update a record with an on_change method . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3.4 Some model methods does not accept the context parameter . . . . . . . . . . . . . . . . . 15
3.3.5 Change the behaviour of a script according to the version of Odoo . . . . . . . . . . . . . . 15
3.4 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.1 Browse object fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.2 odoorpc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.3 odoorpc.ODOO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.4 odoorpc.db . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4.5 odoorpc.report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.6 odoorpc.models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.4.7 odoorpc.env . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.4.8 odoorpc.rpc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.4.9 odoorpc.session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.4.10 odoorpc.tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.4.11 odoorpc.error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
i
4 Supported Odoo server versions 35
6 License 39
7 Bug Tracker 41
8 Credits 43
8.1 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
8.2 Maintainer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
ii
CHAPTER 1
Introduction
OdooRPC is a Python package providing an easy way to pilot your Odoo servers through RPC.
Features supported:
• access to all data model methods (even browse) with an API similar to the server-side API,
• use named parameters with model methods,
• user context automatically sent providing support for internationalization,
• browse records,
• execute workflows,
• manage databases,
• reports downloading,
• JSON-RPC protocol (SSL supported),
1
OdooRPC Documentation, Release 0.6.2
2 Chapter 1. Introduction
CHAPTER 2
Quick start
import odoorpc
# Login
odoo.login('db_name', 'user', 'passwd')
# Current user
user = odoo.env.user
print(user.name) # name of the user connected
print(user.company_id.name) # the name of its company
For more details and features, see the tutorials, the Frequently Asked Questions (FAQ) and the API reference sections.
3
OdooRPC Documentation, Release 0.6.2
Contents
No dependency is required.
The project is hosted on GitHub. To get the last stable release (master branch), just type:
Also, the project uses the Git Flow extension to manage its branches and releases. If you want to contribute, make
sure to make your Pull Request against the develop branch.
Unit tests depend on the standard module unittest (Python 2.7 and 3.x) and on a running Odoo instance. To run all unit
tests from the project directory, run the following command:
5
OdooRPC Documentation, Release 0.6.2
To configure the connection to the server, some environment variables are available:
$ export ORPC_TEST_PROTOCOL=jsonrpc
$ export ORPC_TEST_HOST=localhost
$ export ORPC_TEST_PORT=8069
$ export ORPC_TEST_DB=odoorpc_test
$ export ORPC_TEST_USER=admin
$ export ORPC_TEST_PWD=admin
$ export ORPC_TEST_VERSION=10.0
$ export ORPC_TEST_SUPER_PWD=admin
$ python -m unittest discover -v
3.2 Tutorials
Note: The tutorial is based on Odoo 10.0, the examples must be adapted following the version of Odoo you are using.
To dialog with your Odoo server, you need an instance of the odoorpc.ODOO class. Let’s instanciate it:
Two protocols are available: jsonrpc and jsonrpc+ssl. Then, create your database for the purposes of this
tutorial (you need to know the super admin password to do this):
The creation process may take some time on the server. If you get a timeout error, set a higher timeout before repeating
the process:
To check available databases, use the odoo.db property with the list method:
>>> odoo.db.list()
['tutorial']
Use the login method on a database with the account of your choice:
6 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Note: Under the hood the login method creates a cookie, and all requests thereafter which need a user authentication
are cookie-based.
Once logged in, you can check some information through the environment:
>>> odoo.env.db
'tutorial'
>>> odoo.env.context
{'lang': 'fr_FR', 'tz': 'Europe/Brussels', 'uid': 1}
>>> odoo.env.uid
1
>>> odoo.env.lang
'fr_FR'
>>> odoo.env.user.name # name of the user
'Administrator'
>>> odoo.env.user.company_id.name # the name of its company
'YourCompany'
From now, you can easily execute any kind of queries on your Odoo server (execute model methods, trigger workflow,
download reports. . . ).
Next step: Execute RPC queries
The basic methods to execute RPC queries related to data models are execute and execute_kw. They take at least
two parameters (the model and the name of the method to call) following by additional variable parameters according
to the method called:
This instruction will call the read method of the sale.order model for the order ID=1, and will only returns the
value of the field name.
However there is a more efficient way to perform methods of a model by getting a proxy of it with the model
registry, which provides an API almost syntactically identical to the Odoo server side API (see odoorpc.
models.Model), and which is able to send the user context automatically:
3.2. Tutorials 7
OdooRPC Documentation, Release 0.6.2
Note: The auto_context option only affect methods called from model proxies.
Here is another example of how to install a module (you have to be logged as an administrator to perform this task):
A great functionality of OdooRPC is its ability to generate objects that are similar to records used on the server side.
Get records
To get one or more records (a recordset), you will use the browse method from a model proxy:
From such objects, it is possible to easily explore relationships. The related records are generated on the fly:
Outside relation fields, Python data types are used, like datetime.date and datetime.datetime:
To get a record through its external ID, use the ref method from the environment:
8 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Unlike the Odoo API, there is a difference between class methods (e.g.: create, search, . . . ) and instance methods that
apply directly on existing records (write, read, . . . ):
When a method is called directly on records, their ids (here user.ids) is simply passed as the first parameter. This also
means that you are not able to call class methods such as create or search from a set of records:
This is a behaviour by design: OdooRPC has no way to make the difference between a class or an instance method
through RPC, this is why it differs from the Odoo API.
Next step: Update data through records
By default when updating values of a record, the change is automatically sent to the server. Let’s update the name of
a partner:
As one update is equivalent to one RPC query, if you need to update several fields for one record it is encouraged to
use the write method as above
3.2. Tutorials 9
OdooRPC Documentation, Release 0.6.2
Or, deactivate the auto_commit option and commit the changes manually:
Selection
Same as above, except there is a check about the value assigned. For instance, the field type of the res.partner
model accept values contains in ['default', 'invoice', 'delivery', 'contact', 'other']:
Many2one
You can’t put any ID or record, a check is made on the relationship to ensure data integrity:
10 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
one2many and many2many fields can be updated by providing a list of tuple as specified in the Odoo documentation
(link), a list of records, a list of record IDs, an empty list or False:
With a tuple (as documented), no magic here:
With a recordset:
The last two examples are equivalent to the first (they generate a (6, 0, IDS) tuple).
However, if you set an empty list or False, the relation between records will be removed:
>>> user.groups_id = []
>>> user.groups_id
Recordset('res.group', [])
>>> user.groups_id = False
>>> user.groups_id
Recordset('res.group', [])
Another facility provided by OdooRPC is adding and removing objects using Python operators += and -=. As usual,
you can add an ID, a record, or a list of them:
With a list of records:
With an ID only:
>>> user.groups_id -= 4
>>> user.groups_id
Recordset('res.group', [1, 2, 3, 5])
3.2. Tutorials 11
OdooRPC Documentation, Release 0.6.2
Reference
To update a reference field, you have to use either a string or a record object as below:
date and datetime fields accept either string values or datetime.date/datetime.datetime objects.
With datetime.date and datetime.datetime objects:
12 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Another nice feature is the reports generation with the report property. The list method allows you to list all
reports available on your Odoo server (classified by models), while the download method will retrieve a report as a
file (in PDF, HTML. . . depending of the report).
To list available reports:
>>> odoo.report.list()
{u'account.invoice': [{u'name': u'Duplicates', u'report_type': u'qweb-pdf', u'report_
˓→name': u'account.account_invoice_report_duplicate_main'}, {u'name': u'Invoices', u
To download a report:
The method will return a file-like object, you will have to read its content in order to save it on your file-system:
Once you are authenticated with your ODOO instance, you can save your credentials under a code name and use this
one to quickly instantiate a new ODOO class:
By default, these informations are stored in the ~/.odoorpcrc file. You can however use another file:
You can check available sessions with odoorpc.ODOO.list(), and remove them with odoorpc.ODOO.
remove():
3.2. Tutorials 13
OdooRPC Documentation, Release 0.6.2
>>> odoorpc.ODOO.list()
['tutorial']
>>> odoorpc.ODOO.remove('tutorial')
>>> 'tutorial' not in odoorpc.ODOO.list()
True
It was a tough decision, but several reasons motivated the OdooRPC project:
RPC Protocol The first point is about the supported protocol, XML-RPC is kept in Odoo for compatibility reasons
(and will not evolve anymore, maybe removed one day), replaced by the JSON-RPC one. Although these
protocols are almost similar in the way we build RPC requests, some points make JSON-RPC a better and
reliable choice like the way to handle errors raised by the Odoo server (access to the type of exception raised,
the complete server traceback. . . ). To keep a clean and maintainable base code, it would have been difficult to
support both protocols in OERPLib, and it is why OdooRPC only support JSON-RPC.
Another good point with JSON-RPC is the ability to request all server web controllers to reproduce requests
(type=’json’ ones) made by the official Javascript web client. As the code to make such requests is based on
standard HTTP related Python modules, OdooRPC is also able to request HTTP web controllers (type=’http’
ones).
In fact, you could see OdooRPC as a high level API for Odoo with which you could replicate the behaviour of
the official Javascript web client, but in Python.
New server API One goal of OERPLib was to give an API not too different from the server side API to reduce the
learning gap between server-side development and client-side with an RPC library. With the new API which
appears in Odoo 8.0 this is another brake (the old API has even been removed since Odoo 10.0), so the current
API of OERPLib is not anymore consistent. As such, OdooRPC mimics A LOT the new API of Odoo, for more
consistency (see the tutorials).
New brand Odoo OpenERP became Odoo, so what does OERPLib mean? OEWhat? This is obvious for old devel-
opers which start the OpenERP adventure since the early days, but the OpenERP brand is led to disappear, and
it can be confusing for newcomers in the Odoo world. So, OdooRPC speaks for itself.
Maintenance cost, code cleanup OpenERP has evolved a lot since the version 5.0 (2009), making OERPLib hard to
maintain (write tests for all versions before each OERPLib and OpenERP release is very time consuming). All
the compatibility code for OpenERP 5.0 to 7.0 was dropped for OdooRPC, making the project more maintain-
able. Odoo is now a more mature product, and OdooRPC should suffer less about compatibility issues from one
release to another.
As OdooRPC has not the same constraints concerning Python environments where it could be running on, it is
able to work on Python 2.7 to 3.X.
OdooRPC is turned towards the future, so you are encouraged to use or migrate on it for projects based on Odoo >=
8.0. It is more reliable, better covered by unit tests, and almost identical to the server side new API.
First, you have to connect on your Odoo instance, and set a password for your user account in order to active the RPC
interface.
Then, just use the jsonrpc+ssl protocol with the port 443:
14 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
OdooRPC does not provide helpers for such methods currently. A call to an on_change method intend to be executed
from a view and there is no support for that (not yet?) such as fill a form, validate it, etc. . .
But you can emulate an on_change by writing your own function, for instance:
And call it on a record with the desired method and its parameters:
3.3.4 Some model methods does not accept the context parameter
The context parameter is sent automatically for each call to a Model method. But on the side of the Odoo server,
some methods have no context parameter, and OdooRPC has no way to guess it, which results in an nasty exception.
So you have to disable temporarily this behaviour by yourself by setting the auto_context option to False:
You can compare versions of Odoo servers with the v function applied on the ODOO.version property, for instance:
import odoorpc
from odoorpc.tools import v
3.4 Reference
The table below presents the Python types returned by OdooRPC for each Odoo fields used by Recordset objects
(see the browse method):
3.4.2 odoorpc
3.4.3 odoorpc.ODOO
OdooRPC will try by default to detect the server version in order to adapt its requests if necessary. However, it
is possible to force the version to use with the version parameter:
16 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
You can also define a custom URL opener to handle HTTP requests. A use case is to manage a basic HTTP
authentication in front of Odoo:
Python 2:
Raise odoorpc.error.InternalError
Raise ValueError (wrong protocol, port value, timeout value)
Raise urllib2.URLError (connection error)
Python 3:
Raise odoorpc.error.InternalError
Raise ValueError (wrong protocol, port value, timeout value)
Raise urllib.error.URLError (connection error)
config
Dictionary of available configuration options.
>>> odoo.config
{'auto_commit': True, 'auto_context': True, 'timeout': 120}
• auto_commit: if set to True (default), each time a value is set on a record field a RPC request is
sent to the server to update the record (see odoorpc.env.Environment.commit()).
• auto_context: if set to True (default), the user context will be sent automatically to every call of
a model method (default: True):
• timeout: set the maximum timeout in seconds for a RPC request (default: 120):
db
The database management service. See the odoorpc.db.DB class.
env
The environment which wraps data to manage records such as the user context and the registry to access
data model proxies.
3.4. Reference 17
OdooRPC Documentation, Release 0.6.2
Python 2:
Returns the result returned by the method called
Raise odoorpc.error.RPCError
Raise odoorpc.error.InternalError (if not logged)
Raise urllib2.URLError (connection error)
Python 3:
Returns the result returned by the method called
Raise odoorpc.error.RPCError
Raise odoorpc.error.InternalError (if not logged)
Raise urllib.error.URLError (connection error)
execute_kw(model, method, args=None, kwargs=None)
Execute the method of model. args is a list of parameters (in the right order), and kwargs a dictionary
(named parameters). Both varies according to the method used.
Python 2:
Returns the result returned by the method called
Raise odoorpc.error.RPCError
Raise odoorpc.error.InternalError (if not logged)
18 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Note: For low level JSON-RPC queries, see the more convenient odoorpc.ODOO.json() method
instead.
You have to know the names of each POST parameter required by the URL, and set them in the data
string/buffer. The data argument must be built by yourself, following the expected URL parameters (with
urllib.urlencode() function for simple parameters, or multipart/form-data structure to handle file
upload).
E.g., the HTTP raw query to get the company logo on Odoo 10.0:
Python 2:
Returns urllib.addinfourl
Raise urllib2.HTTPError
Raise urllib2.URLError (connection error)
Python 3:
Returns http.client.HTTPResponse
Raise urllib.error.HTTPError
Raise urllib.error.URLError (connection error)
json(url, params)
Low level method to execute JSON queries. It basically performs a request and raises an odoorpc.
error.RPCError exception if the response contains an error.
You have to know the names of each parameter required by the function called, and set them in the params
dictionary.
Here an authentication request:
3.4. Reference 19
OdooRPC Documentation, Release 0.6.2
Python 2:
Returns a dictionary (JSON response)
Raise odoorpc.error.RPCError
Raise urllib2.HTTPError (if params is not a dictionary)
Raise urllib2.URLError (connection error)
Python 3:
Returns a dictionary (JSON response)
Raise odoorpc.error.RPCError
Raise urllib.error.HTTPError (if params is not a dictionary)
Raise urllib.error.URLError (connection error)
classmethod list(rc_file=’~/.odoorpcrc’)
Return a list of all stored sessions available in the rc_file file:
20 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Python 2:
Raise odoorpc.error.RPCError
Raise urllib2.URLError (connection error)
Python 3:
Raise odoorpc.error.RPCError
Raise urllib.error.URLError (connection error)
logout()
Log out the user.
>>> odoo.logout()
True
Python 2:
Returns True if the operation succeed, False if no user was logged
Raise odoorpc.error.RPCError
Raise urllib2.URLError (connection error)
Python 3:
Returns True if the operation succeed, False if no user was logged
Raise odoorpc.error.RPCError
Raise urllib.error.URLError (connection error)
port
The port used.
protocol
The protocol used.
classmethod remove(name, rc_file=’~/.odoorpcrc’)
Remove the session identified by name from the rc_file file:
3.4. Reference 21
OdooRPC Documentation, Release 0.6.2
Python 2:
Raise ValueError (if the session does not exist)
Raise IOError
Python 3:
Raise ValueError (if the session does not exist)
Raise PermissionError
Raise FileNotFoundError
report
The report management service. See the odoorpc.report.Report class.
save(name, rc_file=’~/.odoorpcrc’)
Save the current ODOO instance (a session) inside rc_file (~/.odoorpcrc by default). This session will
be identified by name:
Use the list class method to list all stored sessions, and the load class method to retrieve an already-
connected ODOO instance.
Python 2:
Raise odoorpc.error.InternalError (if not logged)
Raise IOError
Python 3:
Raise odoorpc.error.InternalError (if not logged)
Raise PermissionError
Raise FileNotFoundError
version
The version of the server.
>>> odoo.version
'10.0'
3.4.4 odoorpc.db
22 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
change_password(password, new_password)
Change the administrator password by new_password.
>>> odoo.db.change_password('super_admin_passwd', 'new_admin_passwd')
If you get a timeout error, increase this one before performing the request:
>>> timeout_backup = odoo.config['timeout']
>>> odoo.config['timeout'] = 600 # Timeout set to 10 minutes
>>> odoo.db.create('super_admin_passwd', 'prod', False, 'fr_FR', 'my_admin_
˓→passwd')
3.4. Reference 23
OdooRPC Documentation, Release 0.6.2
If you get a timeout error, increase this one before performing the request:
You can manipulate the file with the zipfile module for instance:
24 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
>>> odoo.db.list()
['prod', 'test']
Python 2:
Returns list of database names
Raise urllib2.URLError (connection error)
Python 3:
Returns list of database names
Raise urllib.error.URLError (connection error)
restore(password, db, dump, copy=False)
Restore the dump database into the new db database. The dump file object can be obtained with the dump
method. If copy is set to True, the restored database will have a new UUID.
If you get a timeout error, increase this one before performing the request:
3.4. Reference 25
OdooRPC Documentation, Release 0.6.2
3.4.5 odoorpc.report
This module provide the Report class to list available reports and to generate/download them.
class odoorpc.report.Report(odoo)
The Report class represents the report management service. It provides methods to list and download available
reports from the server.
Python 2:
Returns io.BytesIO
Raise odoorpc.error.RPCError (wrong parameters)
Raise ValueError (received invalid data)
Raise urllib2.URLError (connection error)
Python 3:
Returns io.BytesIO
Raise odoorpc.error.RPCError (wrong parameters)
Raise ValueError (received invalid data)
Raise urllib.error.URLError (connection error)
list()
List available reports from the server by returning a dictionary with reports classified by data model:
>>> odoo.report.list()['account.invoice']
[{'name': u'Duplicates',
'report_name': u'account.account_invoice_report_duplicate_main',
'report_type': u'qweb-pdf'},
{'name': 'Invoices',
(continues on next page)
26 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Python 2:
Returns list of dictionaries
Raise urllib2.URLError (connection error)
Python 3:
Returns list of dictionaries
Raise urllib.error.URLError (connection error)
3.4.6 odoorpc.models
Provide the Model class which allow to access dynamically to all methods proposed by a data model.
class odoorpc.models.Model
Base class for all data model proxies.
Note: All model proxies (based on this class) are generated by an environment (see the odoorpc.ODOO.
env property).
Get a recordset:
And call any method from it, it will be automatically applied on the current record:
[[1, 'Administrator']]
Warning: Excepted the browse method, method calls are purely dynamic. As long as you know the
signature of the model method targeted, you will be able to use it (see the tutorial).
__eq__(other)
x.__eq__(y) <==> x==y
3.4. Reference 27
OdooRPC Documentation, Release 0.6.2
__getattr__(method)
Provide a dynamic access to a RPC instance method (which applies on the current recordset).
__getitem__(key)
If key is an integer or a slice, return the corresponding record selection as a recordset.
__init__()
x.__init__(. . . ) initializes x; see help(type(x)) for signature
__iter__()
Return an iterator over self.
__ne__(other)
x.__ne__(y) <==> x!=y
__repr__() <==> repr(x)
classmethod browse(ids)
Browse one or several records (if ids is a list of IDs).
>>> odoo.env['res.partner'].browse(1)
Recordset('res.partner', [1])
A list of data types returned by such record fields are available here.
Returns a Model instance (recordset)
Raise odoorpc.error.RPCError
id
ID of the record (or the first ID of a recordset).
ids
IDs of the recorset.
with_context(*args, **kwargs)
Return an instance equivalent to self attached to an environment based on self.env with another context.
The context is taken from self.env or from the positional argument if given, and modified by kwargs.
Thus, the following two examples are equivalent:
28 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
with_env(env)
Return an instance equivalent to self attached to env.
3.4.7 odoorpc.env
__contains__(model)
Check if the given model exists on the server.
>>> 'res.partner' in odoo.env
True
__getitem__(model)
Return the model class corresponding to model.
>>> Partner = odoo.env['res.partner']
>>> Partner
Model('res.partner')
context
The context of the user connected.
>>> odoo.env.context
{'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1}
db
The database currently used.
>>> odoo.env.db
'db_name'
3.4. Reference 29
OdooRPC Documentation, Release 0.6.2
lang
Return the current language code.
>>> odoo.env.lang
'en_US'
ref(xml_id)
Return the record corresponding to the given xml_id (also called external ID). Raise an RPCError if no
record is found.
>>> odoo.env.ref('base.lang_en')
Recordset('res.lang', [1])
registry
The data model registry. It is a mapping between a model name and its corresponding proxy used to
generate records. As soon as a model is needed the proxy is added to the registry. This way the model
proxy is ready for a further use (avoiding costly RPC queries when browsing records through relations).
>>> odoo.env.registry
{}
>>> odoo.env.user.company_id.name # 'res.users' and 'res.company' Model
˓→proxies will be fetched
'YourCompany'
>>> from pprint import pprint
>>> pprint(odoo.env.registry)
{'res.company': Model('res.company'), 'res.users': Model('res.users')}
If you need to regenerate the model proxy, simply delete it from the registry:
>>> odoo.env.registry.clear()
>>> odoo.env.registry
{}
uid
The user ID currently logged.
>>> odoo.env.uid
1
user
Return the current user (as a record).
30 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
Raise odoorpc.error.RPCError
3.4.8 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.
ssl
Return True if SSL is activated.
timeout
Return the timeout.
class odoorpc.rpc.ConnectorJSONRPC(host, port=8069, timeout=120, version=None, deserial-
ize=True, opener=None)
Connector class using the JSON-RPC protocol.
{'id': 51373612,
'jsonrpc': '2.0',
'result': {'company_id': 1,
'currencies': {'1': {'digits': [69, 2],
'position': 'after',
'symbol': '\u20ac'},
'3': {'digits': [69, 2],
'position': 'before',
'symbol': '$'}},
'db': 'db_name',
'is_admin': True,
'is_superuser': True,
'name': 'Administrator',
'partner_id': 3,
'server_version': '10.0',
'server_version_info': [10, 0, 0, 'final', 0, ''],
'session_id': '6dd7a34f16c1c67b38bfec413cca4962d5c01d53',
'uid': 1,
'user_companies': False,
'user_context': {'lang': 'en_US',
'tz': 'Europe/Brussels',
'uid': 1},
'username': 'admin',
'web.base.url': 'http://localhost:8069',
'web_tours': []}}
3.4. Reference 31
OdooRPC Documentation, Release 0.6.2
Or like this:
proxy_http
Return the HTTP proxy.
proxy_json
Return the JSON proxy.
timeout
Return the timeout.
class odoorpc.rpc.ConnectorJSONRPCSSL(host, port=8069, timeout=120, version=None, deseri-
alize=True, opener=None)
Connector class using the JSON-RPC protocol over SSL.
3.4.9 odoorpc.session
This module contains some helper functions used to save and load sessions in OdooRPC.
odoorpc.session.get(name, rc_file=’~/.odoorpcrc’)
Return the session configuration identified by name from the rc_file file.
32 Chapter 3. Contents
OdooRPC Documentation, Release 0.6.2
odoorpc.session.get_all(rc_file=’~/.odoorpcrc’)
Return all session configurations from the rc_file file.
odoorpc.session.remove(name, rc_file=’~/.odoorpcrc’)
Remove the session configuration identified by name from the rc_file file.
3.4.10 odoorpc.tools
This module contains the Config class which manage the configuration related to an instance of ODOO, and some
useful helper functions used internally in OdooRPC.
class odoorpc.tools.Config(odoo, options)
Class which manage the configuration of an ODOO instance.
odoorpc.tools.clean_version(version)
Clean a version string.
3.4. Reference 33
OdooRPC Documentation, Release 0.6.2
odoorpc.tools.get_encodings(hint_encoding=’utf-8’)
Used to try different encoding. Function copied from Odoo 11.0 (odoo.loglevels.get_encodings). This piece of
code is licensed under the LGPL-v3 and so it is compatible with the LGPL-v3 license of OdooRPC:
- https://github.com/odoo/odoo/blob/11.0/LICENSE
- https://github.com/odoo/odoo/blob/11.0/COPYRIGHT
odoorpc.tools.v(version)
Convert a version string to a tuple. The tuple can be use to compare versions between them.
3.4.11 odoorpc.error
This module contains all exceptions raised by OdooRPC when an error occurred.
exception odoorpc.error.Error
Base class for exception.
exception odoorpc.error.InternalError
Exception raised for errors occurring during an internal operation.
exception odoorpc.error.RPCError(message, info=False)
Exception raised for errors related to RPC queries. Error details (like the Odoo server traceback) are available
through the info attribute:
34 Chapter 3. Contents
CHAPTER 4
OdooRPC has been tested on Odoo 8.0, 9.0, 10.0 and 11.0. It should work on next versions if Odoo keeps a stable
API.
35
OdooRPC Documentation, Release 0.6.2
37
OdooRPC Documentation, Release 0.6.2
License
39
OdooRPC Documentation, Release 0.6.2
40 Chapter 6. License
CHAPTER 7
Bug Tracker
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If
you spotted it first, help us smash it by providing detailed and welcomed feedback.
41
OdooRPC Documentation, Release 0.6.2
Credits
8.1 Contributors
8.2 Maintainer
43
OdooRPC Documentation, Release 0.6.2
44 Chapter 8. Credits
CHAPTER 9
• genindex
• modindex
• search
45
OdooRPC Documentation, Release 0.6.2
o
odoorpc, 16
odoorpc.db, 22
odoorpc.env, 29
odoorpc.error, 34
odoorpc.models, 27
odoorpc.report, 26
odoorpc.rpc, 31
odoorpc.session, 32
odoorpc.tools, 33
47
OdooRPC Documentation, Release 0.6.2
49
OdooRPC Documentation, Release 0.6.2
odoorpc.report (module), 26
odoorpc.rpc (module), 31
odoorpc.session (module), 32
odoorpc.tools (module), 33
P
port (odoorpc.ODOO attribute), 21
protocol (odoorpc.ODOO attribute), 21
proxy_http (odoorpc.rpc.ConnectorJSONRPC attribute),
32
proxy_json (odoorpc.rpc.ConnectorJSONRPC attribute),
32
R
ref() (odoorpc.env.Environment method), 30
registry (odoorpc.env.Environment attribute), 30
remove() (in module odoorpc.session), 33
remove() (odoorpc.ODOO class method), 21
Report (class in odoorpc.report), 26
report (odoorpc.ODOO attribute), 22
restore() (odoorpc.db.DB method), 25
RPCError, 34
S
save() (in module odoorpc.session), 33
save() (odoorpc.ODOO method), 22
ssl (odoorpc.rpc.Connector attribute), 31
T
timeout (odoorpc.rpc.Connector attribute), 31
timeout (odoorpc.rpc.ConnectorJSONRPC attribute), 32
U
uid (odoorpc.env.Environment attribute), 30
user (odoorpc.env.Environment attribute), 30
V
v() (in module odoorpc.tools), 34
version (odoorpc.ODOO attribute), 22
W
with_context() (odoorpc.models.Model method), 28
with_env() (odoorpc.models.Model method), 29
50 Index