openerp_proxy Package

core Module

This module provides some classes to simplify access to Odoo server via xmlrpc.

Example ussage of this module

>>> cl = Client('', 'dbname', 'some_user', 'mypassword')
>>> sale_obj = cl['sale_order']
>>> sale_ids =[('state','not in',['done','cancel'])])
>>> sale_data =, ['name'])
>>> for order in sale_data:
...     print("%5s :    %s" % (order['id'],order['name']))
>>> product_tmpl_obj = cl['product.template']
>>> product_obj = cl['product.product']
>>> tmpl_ids =[('name','ilike','template_name')])
>>> print([('product_tmpl_id','in',tmpl_ids)]))

>>> db = Client('', 'dbname='db0', user='your_user')
>>> so = db['sale.order']
>>> order_ids =[('state','=','done')])
>>> order =[0])

Also You can call any method (beside private ones starting with underscore(_)) of any model. For example following code allows to check availability of stock moves:

>>> db = session.connect()
>>> move_obj = db['stock.move']
>>> move_ids = [1234] # IDs of stock moves to be checked
>>> move_obj.check_assign(move_ids)

Ability to use Record class as analog to browse_record:

>>> move_obj = db['stock.move']
>>> move = move_obj.browse(1234)
>>> move.state
... 'confirmed'
>>> move.check_assign()
>>> move.refresh()
>>> move.state
... 'assigned'
>>> move.picking_id
... R('stock.picking', 12)['OUT-12']
... 12
... 'OUT-12'
>>> move.picking_id_.state
... 'assigned'

session Module

class openerp_proxy.session.Session(data_file='~/.openerp_proxy.json')[source]

Bases: extend_me.Extensible, odoo_rpc_client.utils.DirMixIn

Simple session manager which allows to manage databases easier This class stores information about databases You used in home directory, and on init it loads history and allows simply connect to database by url or index. No more hosts, usernames, ports, etc… required to be memorized. Just on session start call:

>>> print(session)

And You will get all databases You worked with listed as (index, url) pairs. To connect to one of thouse databases just call session[index|url] and required Client object will be returned.

Parameters:data_file (string) – path to session file

Add db to session.

Parameters:db (openerp_proxy.core.Client) – database (client instance) to be added to session

Adds extra path to python import path.

Parameters:path (string) – Paths to be added

Note: this way path will be saved in session

aliase(name, val)[source]

Sets up aliase ‘name’ for val

  • name (string) – new aliase
  • val (int|string|Client instance) – database to create aliase for

val could be index, url or Client object:

session.aliase('tdb', 1)
session.aliase('mdb', 'xml-rpc://')
session.aliase('xdb', db)

And now You can use this aliase like:

Returns:unchanged val

List of database aliases

To add new database aliase, use method aliase:

session.aliase('mdb', db)  # db is instance of Client
connect(host=None, dbname=None, user=None, pwd=None, port=8069, protocol='xml-rpc', interactive=True, no_save=False)[source]

Wraper around Client constructor class to simplify connect from shell.

  • host (str) – host name to connect to (will be asked interactvely if not provided)
  • dbname (str) – name of database to connect to (will be asked interactvely if not provided)
  • user (str) – user name to connect as (will be asked interactvely if not provided)
  • pwd (str) – password for selected user (will be asked interactvely if not provided)
  • port (int) – port to connect to. (default: 8069)
  • interactive (bool) – ask for connection parameters if not provided. (default: True)
  • no_save (bool) – if set to True database will not be saved to session

Client object


Returns list of URLs of databases available in current session

Returns:list of urls of databases from session
Return type:list of strings

Remove database from session

Parameters:db (openerp_proxy.core.Client) – database (client instance) to be removed from session

List of extra pyhton paths, used by this session


Returns instance of Client object, that represents single Odoo database it connected to, specified by passed index (integer) or url (string) of database, previously saved in session.

Parameters:url_or_index (int|string) – must be integer (if index) or string (if url). this parametr specifies database to get from session
Returns:Client instance
Raises:ValueError – if cannot find database by specified args


session.get_db(1)   # using index
session.get_db('my_db')   # using aliase

Property which returns dict with {index: url}


Reverse index.

Property which returns dict with {url: index}

option(opt, val=None, default=None)[source]

Get or set option. if val is passed, val will be set as value for option, else just option value will be returned

  • opt (str) – option to get or set value for
  • val – value to be set for option opt

value of option opt

Currently available options:

  • store_passwords (bool) If set to True then all used passwords will be stored on But be careful, because of encription used for stored passwords is very week.

Saves session on disk


List of start-up imports

If You want some module to be automaticaly imported on when session starts, that just add it to this list:


exceptions Module

plugin Module

utils Module

class openerp_proxy.utils.AttrDict[source]

Bases: dict, odoo_rpc_client.utils.DirMixIn

Simple class to make dictionary able to use attribute get operation to get elements it contains using syntax like:

>>> d = AttrDict(arg1=1, arg2='hello')
>>> print(d.arg1)
>>> print(d.arg2)
>>> print(d['arg2'])
>>> print(d['arg1'])
class openerp_proxy.utils.DirMixIn[source]

Bases: object

class openerp_proxy.utils.UConverter(hint_encodings=None)[source]

Bases: object

Simple converter to unicode

Create instance with specified list of encodings to be used to try to convert value to unicode


ustr = UConverter(['utf-8', 'cp-1251'])
my_unicode_str = ustr(b'hello - привет')
default_encodings = ['utf-8', 'ascii']
openerp_proxy.utils.wpartial(func, *args, **kwargs)[source]

Wrapped partial, same as functools.partial decorator, but also calls functools.wrap on its result thus shwing correct function name and representation.


os.makedirs wrapper. No errors raised if directory already exists

Parameters:path (str) – directory path to create

Read specified json file

openerp_proxy.utils.json_write(file_path, *args, **kwargs)[source]

Write data to specified json file

Note, this function uses dumps function to convert data to json first, and write only if conversion is successfule. This allows to avoid loss of data when rewriting file.


Read a string from standard input. The trailing newline is stripped.

The prompt string, if given, is printed to standard output without a trailing newline before reading input.

If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available.