Reference
This module defines the OERP and DMS classes.
The OERP class manage the client-side operations which are related to an OpenERP
server. You can use this to write Python programs that performs a variety of
automated jobs that communicate with an OpenERP server.
Here’s a sample session using the oerplib module:
>>> import oerplib
>>> oerp = oerplib.OERP('localhost') # connect to localhost, default port
>>> user = oerp.login('admin', 'admin') # login returns an user object
>>> user.name
'Administrator'
OERP Class
-
class oerplib.OERP(server, database=None, port=8069)
Return a new instance of the OERP class.
The optional database parameter specifies the default database to use
when the login(user, passwd) is called. By default, the port 8069
is used.
-
browse(osv_name, ids, refresh=True)
- Return a browsable object (or a list of objects)
according to the OSV name and ID (or IDs) supplied.
refresh option will reinitialize the object if this one has
already been loaded previously (this is the default behaviour, set to
False to change that).
-
create(osv_name, vals)
- Create a new record with the specified values contained in the
vals dictionary (e.g. {'name': 'John', ...}).
Return the ID of the new record.
-
exec_report(report_name, osv_name, obj_id, report_type='pdf')
Download a report from the OpenERP server via XMLRPC
and return the path of the file.
WARNING: not sufficiently tested.
-
exec_workflow(*args)
XMLRPC Workflow query.
WARNING: not sufficiently tested.
-
execute(osv_name, method, *args)
- Execute a simple XMLRPC method method on the OSV server class
osv_name. *args parameters varies according to the method used.
-
get_osv_name(osv_obj)
- Return the OSV name of the OSV instance osv_obj supplied.
-
login(user, passwd, database=None)
- Log in as the given user with the password passwd on the
database database and return the corresponding User browsable
object.
If database is not specified, the default one will be used instead.
If no database is found, a LoginError exception will be raised.
-
read(osv_name, ids, fields=[])
- 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.
-
refresh(osv_obj)
- Restore original values of the object osv_obj from data
retrieved on the OpenERP server.
Thus, all changes made locally on the object are canceled.
-
reset(osv_obj)
- Cancel all changes made locally on the object osv_obj.
No request to the server is executed to perform this operation.
Therefore, values restored may be outdated.
-
search(osv_name, args)
- Return a list of IDs of records matching the given criteria in
args parameter. args must be of the form
[('name', '=', 'John'), (...)]
-
unlink(osv, ids=[])
- Delete records with the given IDs (e.g. [1, 42, ...]).
osv parameter may be the OSV server class name
(e.g. 'sale.order') or an OSV instance (browsable object).
In the latter case, the parameter ids is useless.
Return True.
-
write(osv, ids=[], vals={})
- Update records with given IDs (e.g. [1, 42, ...])
with the given values contained in the vals dictionary
(e.g. {'name': 'John', ...}).
osv parameter may be the OSV server class name
(e.g. 'sale.order') or an OSV instance (browsable object).
In the latter case, vals will automatically contain all the changed
values of the object and ids the object ID, thus the parameters
ids and vals are useless.
Return True.
Field types
The table below presents the Python types used for each OpenERP fields:
OpenERP fields |
Python types used in OERPLib |
fields.binary |
? |
fields.boolean |
bool |
fields.char |
basestring |
fields.date |
datetime.date |
fields.datetime |
datetime.datetime |
fields.float |
float |
fields.integer |
integer |
fields.selection |
basestring |
fields.text |
basestring |
Exceptions made for relation fields:
OpenERP fields |
Types used in OERPLib |
fields.many2one |
OSV object |
fields.one2many |
list of OSV objects |
fields.many2many |
list of OSV objects |