oerplib.OERP

class oerplib.OERP(server, database=None, protocol='xmlrpc', port=8069)

Return a new instance of the OERP class. The optional database parameter specifies the default database to use when the login method is called. If no database is set, the database parameter of the login method will be mandatory.

XML-RPC (by default, with the port 8069) and Net-RPC protocols are supported. Respective values for the protocol parameter are xmlrpc and netrpc.

>>> import oerplib
>>> oerp = oerplib.OERP('localhost', protocol='netrpc', port=8070)
Raise:oerplib.error.InternalError
browse(osv_name, ids, context=None)

Return a browsable record (or a list of records if ids is a list) according to the model osv_name.

>>> oerp.browse('res.partner', 1)
browse_record(res.partner, 1)
>>> [partner.name for partner in oerp.browse('res.partner', [1, 2])]
[u'Your Company', u'ASUStek']
Returns:a BrowseRecord instance
Raise:oerplib.error.RPCError
create(osv_name, vals, context=None)

Create a new record with the specified values contained in the vals dictionary (e.g. {'name': 'John', ...}).

>>> partner_id = oerp.create('res.partner', {'name': 'Jacky Bob', 'lang': 'fr_FR'})
Returns:the ID of the new record.
Raise:oerplib.error.RPCError
database
The database currently used.
db

New in version 0.4.0.

The database management service. See the oerplib.service.db.DB class.

exec_workflow(osv_name, signal, obj_id)

XML-RPC Workflow query. Execute the workflow signal signal on the instance having the ID obj_id of OSV server class osv_name.

Raise:oerplib.error.RPCError

WARNING: not sufficiently tested.

execute(osv_name, method, *args)

Execute a simple XML-RPC method on the OSV server class osv_name. *args parameters varies according to the method used.

>>> oerp.execute('res.partner', 'read', [1, 2], ['name'])
[{'name': u'ASUStek', 'id': 2}, {'name': u'Your Company', 'id': 1}]
Returns:the result returned by the method called
Raise:oerplib.error.RPCError
get_osv_name(browse_record)

Return the OSV server class name of the browse_record supplied.

>>> partner = oerp.browse('res.partner', 1)
>>> oerp.get_osv_name(partner)
'res.partner'
Returns:the OSV server class name of the browsable record
login(user, passwd, database=None)

Log in as the given user with the password passwd on the database database and return the corresponding user as a browsable record (from the res.users model). If database is not specified, the default one will be used instead.

>>> user = oerp.login('admin', 'admin', database='db_name')
>>> user.name
u'Administrator'
Returns:the user connected as a browsable record
Raise:oerplib.error.RPCError
port
The port used.
protocol
The protocol used.
read(osv_name, ids, fields=None, context=None)

Return the ID of each record with the values of the requested fields fields from the OSV server class osv_name. If fields is not specified, all fields values will be retrieved.

>>> oerp.read('res.partner', [1, 2], ['name'])
[{'name': u'ASUStek', 'id': 2}, {'name': u'Your Company', 'id': 1}]
Raise:oerplib.error.RPCError
refresh(browse_record)

Restore original values of the browse_record from data retrieved on the OpenERP server. Thus, all changes made locally on the record are canceled.

Raise:oerplib.error.RPCError
report(report_name, osv_name, obj_id, report_type='pdf', context=None)

Download a report from the OpenERP server and return the path of the file.

>>> oerp.report('sale.order', 'sale.order', 1)
'/tmp/oerplib_uJ8Iho.pdf'
Returns:the path to the generated temporary file
Raise:oerplib.error.RPCError
reset(browse_record)
Cancel all changes made locally on the browse_record. No request to the server is executed to perform this operation. Therefore, values restored may be outdated.
search(osv_name, args=None, offset=0, limit=None, order=None, context=None, count=False)

Return a list of IDs of records matching the given criteria in args parameter. args must be of the form [('name', '=', 'John'), (...)]

>>> oerp.search('res.partner', [('name', 'like', 'Agrolait')])
[3]
Returns:a list of IDs
Raise:oerplib.error.RPCError
server
The server name.

Delete records with the given ids (e.g. [1, 42, ...]). osv_name parameter is the OSV server class name (e.g. 'sale.order').

>>> oerp.unlink('res.partner', [1])
Returns:True
Raise:oerplib.error.RPCError

New in version 0.4.0.

Delete the browse_record from the OpenERP server.

user

The browsable record of the user connected.

>>> oerp.login('admin', 'admin') == oerp.user
True
write(osv_name, ids, vals=None, context=None)

Update records with given ids (e.g. [1, 42, ...]) with the given values contained in the vals dictionary (e.g. {'name': 'John', ...}). osv_name parameter is the OSV server class name (e.g. 'sale.order').

>>> oerp.write('res.users', [1], {'name': u"Administrator"})
True
Returns:True
Raise:oerplib.error.RPCError
write_record(browse_record, context=None)

New in version 0.4.0.

Update the field values of browse_record by sending them to the OpenERP server (only field values which have been changed).

Field types

The table below presents the Python types returned by OERPLib for each OpenERP fields:

OpenERP fields Python types used in OERPLib
fields.binary basestring (str or unicode)
fields.boolean bool
fields.char basestring (str or unicode)
fields.date datetime.date
fields.datetime datetime.datetime
fields.float float
fields.integer integer
fields.selection basestring (str or unicode)
fields.text basestring (str or unicode)

Exceptions made for relation fields:

OpenERP fields Types used in OERPLib
fields.many2one oerplib.service.osv.browse.BrowseRecord object
fields.one2many list of oerplib.service.osv.browse.BrowseRecord objects
fields.many2many list of oerplib.service.osv.browse.BrowseRecord objects

Table Of Contents

Previous topic

oerplib

Next topic

oerplib.OERP.db

This Page