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 and Net-RPC protocols are supported. Respective values for the protocol parameter are xmlrpc, xmlrpc+ssl and netrpc.
>>> import oerplib
>>> oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=8069)
Since the version 0.7, OERPLib will try by default to detect the server version in order to adapt its requests. However, it is possible to force the version to use with the version parameter:
>>> oerp = oerplib.OERP('localhost', version='6.0')
Raise: | oerplib.error.InternalError, oerplib.error.RPCError |
---|
Browse one or several records (if ids is a list of IDs) from model. The fields and values for such objects are generated dynamically.
>>> 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']
A list of data types used by browse_record fields are available here.
Returns: | a browse_record instance |
---|---|
Returns: | a generator to iterate on browse_record instances |
Raise: | oerplib.error.RPCError |
New in version 0.6.
The common service (/common RPC service). See the oerplib.service.common.Common class.
Dictionary of available configuration options.
>>> oerp.config
{'auto_context': True, 'timeout': 120}
auto_context: if set to True, the user context will be sent automatically to every call of a model method (default: True):
New in version 0.7.
Note
This option only works on servers in version 6.1 and above.
>>> product_osv = oerp.get('product.product') >>> product_osv.name_get([3]) # Context sent by default ('lang': 'fr_FR' here) [[3, '[PC1] PC Basic']] >>> oerp.config['auto_context'] = False >>> product_osv.name_get([3]) # No context sent [[3, '[PC1] Basic PC']]
timeout: set the maximum timeout in seconds for a RPC request (default: 120):
New in version 0.6.
>>> oerp.config['timeout'] = 300
The context of the user connected.
>>> oerp.login('admin', 'admin')
browse_record('res.users', 1)
>>> oerp.context
{'lang': 'fr_FR', 'tz': False}
>>> oerp.context['lang'] = 'en_US'
Create a new model record with values contained in the vals dictionary.
>>> partner_id = oerp.create('res.partner', {'name': 'Jacky Bob', 'lang': 'fr_FR'})
Returns: | the ID of the new record. |
---|---|
Raise: | oerplib.error.RPCError |
The database currently used.
New in version 0.4.
The database management service (/db RPC service). See the oerplib.service.db.DB class.
Execute the workflow signal on the instance having the ID obj_id of model.
Raise: | oerplib.error.RPCError |
---|
Execute the method of model. *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 |
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.
>>> oerp.execute_kw('res.partner', 'read', [[1, 2]], {'fields': ['name']})
[{'name': u'ASUStek', 'id': 2}, {'name': u'Your Company', 'id': 1}]
Warning
This method only works on servers in version 6.1 and above.
Returns: | the result returned by the method called |
---|---|
Raise: | oerplib.error.RPCError |
New in version 0.5.
Return a proxy of the model built from the server (see oerplib.service.osv.Model).
Returns: | an instance of oerplib.service.osv.Model |
---|
Deprecated since version 0.7: use the __osv__ attribute instead (see BrowseRecord).
>>> partner = oerp.browse('res.partner', 1)
>>> oerp.get_osv_name(partner)
'res.partner'
Returns: | the model name of the browsable record |
---|
New in version 0.8.
The inspect service (custom service). See the oerplib.service.inspect.Inspect class.
New in version 0.8.
Return a list of all sessions available in the rc_file file:
>>> import oerplib
>>> oerplib.OERP.list()
['foo', 'bar']
Then, use the load() function with the desired session:
>>> oerp = oerplib.OERP.load('foo')
New in version 0.8.
Return a OERP session pre-configured and connected with informations identified by name:
>>> import oerplib
>>> oerp = oerplib.OERP.load('foo')
Such informations are stored with the OERP.save method.
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, oerplib.error.Error |
The port used.
The protocol used.
Return fields values for each model record identified by ids. 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}]
Returns: | list of dictionaries |
---|---|
Raise: | oerplib.error.RPCError |
Restore original values on browse_record with data fetched on the server. As a result, all changes made locally on the record are canceled.
Raise: | oerplib.error.RPCError |
---|
New in version 0.8.
Remove the session identified by name from the rc_file file:
>>> import oerplib
>>> oerplib.OERP.remove('foo')
True
Download a report from the server and return the local path of the file.
>>> oerp.report('sale.order', 'sale.order', 1)
'/tmp/oerplib_uJ8Iho.pdf'
>>> oerp.report('sale.order', 'sale.order', [1, 2])
'/tmp/oerplib_giZS0v.pdf'
Returns: | the path to the generated temporary file |
---|---|
Raise: | oerplib.error.RPCError |
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.
New in version 0.8.
Save the session configuration under the name name. These informations are stored in the ~/.oerplibrc file by default.
>>> import oerplib
>>> oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=8069)
>>> oerp.login('admin', 'admin', 'db_name')
>>> oerp.save('foo')
Such informations can be loaded with the oerplib.load() function by returning a pre-configured session of OERP, or with the oerp command line tool supplied with oerplib.
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 |
The server name.
Delete model records identified by ids.
>>> oerp.unlink('res.partner', [1])
Returns: | True |
---|---|
Raise: | oerplib.error.RPCError |
New in version 0.4.
Delete the record corresponding to browse_record from the server.
>>> partner = oerp.browse('res.partner', 1)
>>> oerp.unlink_record(partner) # unlink('res.partner', [1])
Returns: | True |
---|---|
Raise: | oerplib.error.RPCError |
The browsable record of the user connected.
>>> oerp.login('admin', 'admin') == oerp.user
True
The version of the server.
>>> oerp.version
'7.0-20131014-231047'
New in version 0.6.
The wizard service (/wizard RPC service). See the oerplib.service.wizard.Wizard class.
Update model records identified by ids with the given values contained in the vals dictionary.
>>> oerp.write('res.users', [1], {'name': "Administrator"})
True
Returns: | True |
---|---|
Raise: | oerplib.error.RPCError |
New in version 0.4.
Update the record corresponding to browse_record by sending its values to the server (only field values which have been changed).
>>> partner = oerp.browse('res.partner', 1)
>>> partner.name = "Test"
>>> oerp.write_record(partner) # write('res.partner', [1], {'name': "Test"})
Returns: | True |
---|---|
Raise: | oerplib.error.RPCError |