class oerplib.service.osv.Model(oerp, model)

New in version 0.5.

Represent a data model from the OpenERP server.


This class have to be used through the oerplib.OERP.get() method.

>>> import oerplib
>>> oerp = oerplib.OERP('localhost')
>>> user = oerp.login('admin', 'passwd', 'database')
>>> user_obj = oerp.get('res.users')
>>> user_obj
<oerplib.service.osv.osv.Model object at 0xb75ba4ac>
>>> user_obj.name_get(user.id) # Use any methods from the model instance
[[1, 'Administrator']]


The only method implemented in this class is browse. Except this one, method calls are purely dynamic. As long as you know the signature of the model method targeted, you will be able to use it (see the tutorial).

browse(ids, context=None)

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.get('res.partner').browse(1)
browse_record(res.partner, 1)
>>> [partner.name for partner in oerp.get('res.partner').browse([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


class oerplib.service.osv.BrowseRecord(o_id)

Base class that all browsable records inherit from. No attributes should be defined in this class (except _id/id, __oerp__, __osv__, __data__ and Python magic methods) in order to not be conflicted with the fields defined in the model class on the OpenERP server.

A reference to the OERP object used to instanciate a browse_record is available through the __oerp__ attribute:

>>> oerp = oerplib.OERP('localhost')
>>> user = oerp.login('admin', 'admin', 'db_name')
>>> user.__oerp__ == oerp

The __data__ attribute is used to store some data related to the record (it is not recommended to edit them):

>>> user.__data__
{'updated_values': {},
 'raw_data': {'action_id': False,
              'active': True,
              'company_id': [1, 'Your Company'],
 'values': {'action_id': False,
            'active': True,
            'company_id': [1, 'Your Company'],

In the same way, information about the model class and its columns may be obtained via the __osv__ attribute:

>>> user.__osv__
{'columns': {'action_id': <oerplib.service.osv.fields.Many2OneField object at 0xb75786ec>,
             'active': <oerplib.service.osv.fields.ValueField object at 0xb7598b6c>,
             'company_id': <oerplib.service.osv.fields.Many2OneField object at 0xb757868c>,
 'name': 'res.users'}

ID of the record.

Table Of Contents

Previous topic


Next topic


This Page