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('server.com', 'dbname', 'some_user', 'mypassword')
>>> sale_obj = cl['sale_order']
>>> sale_ids = sale_obj.search([('state','not in',['done','cancel'])])
>>> sale_data = sale_obj.read(sale_ids, ['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 = product_tmpl_obj.search([('name','ilike','template_name')])
>>> print(product_obj.search([('product_tmpl_id','in',tmpl_ids)]))

>>> db = Client('erp.host.com', 'dbname='db0', user='your_user')
>>> so = db['sale.order']
>>> order_ids = so.search([('state','=','done')])
>>> order = so.read(order_ids[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']
>>> move.picking_id.id
... 12
>>> move.picking_id.name
... '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(db)[source]

Add db to session.

Parameters:db (openerp_proxy.core.Client) – database (client instance) to be added to session
add_path(path)[source]

Adds extra path to python import path.

Parameters:path (string) – Paths to be added
Returns:None

Note: this way path will be saved in session

aliase(name, val)[source]

Sets up aliase ‘name’ for val

Parameters:
  • 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://me@my.example.com:8069/my_db')
session.aliase('xdb', db)

And now You can use this aliase like:

session.tdb
session.mdb
session.xdb
Returns:unchanged val
aliases

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.

Parameters:
  • 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
Returns:

Client object

db_list

Returns list of URLs of databases available in current session

Returns:list of urls of databases from session
Return type:list of strings
del_db(db)[source]

Remove database from session

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

List of extra pyhton paths, used by this session

get_db(url_or_index)[source]

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

Examples:

session.get_db(1)   # using index
session.get_db('xml-rpc://katyukha@erp.jbm.int:8069/jbm0')
session.get_db('my_db')   # using aliase
index

Property which returns dict with {index: url}

index_rev

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

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

value of option opt

Currently available options:

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

Saves session on disk

start_up_imports

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:

session.start_up_imports.append('openerp_proxy.ext.sugar')

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)
    1
>>> print(d.arg2)
    hello
>>> print(d['arg2'])
    hello
>>> print(d['arg1'])
    1
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

Example:

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.

openerp_proxy.utils.makedirs(path)[source]

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

Parameters:path (str) – directory path to create
openerp_proxy.utils.json_read(file_path)[source]

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.

openerp_proxy.utils.xinput()

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.