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 |
---|
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 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 |
New in version 0.4.0.
The database management service. See the oerplib.service.db.DB class.
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 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 |
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 |
---|
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 |
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 |
---|
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 |
---|
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 |
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 |
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.
The browsable record of the user connected.
>>> oerp.login('admin', 'admin') == oerp.user
True
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 |
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).
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 |