on_change methods supported?

Asked by Manu


I want to know if OERPLib supports on_change methods from views. Thoses are really necessary. Currently I have been using OOOR a lot and I'm asking about the on_change methods because I prefer to use python instead of ruby if possible, so if the on_change methods are supported I will switch to OERPLib.

Thank you.

Question information

English Edit question
OERPLib Edit question
No assignee Edit question
Solved by:
Sébastien Alix
Last query:
Last reply:
Revision history for this message
Best Sébastien Alix (sebastien-alix) said :

Hi Manu,

I started to work on view management, but it is not planned for the next release. About the 'on_change', there is no "nice integration" of it on browse_record currently (but if the view management module is implemented - one day - it will be part of it).
However, it is not complicated for you to implement that on your side, as 'on_change' is just a normal Model method:

import oerplib
oerp = oerplib.OERP(...)

order_obj = oerp.get('sale.order')
order = order_obj.browse(1)
# Update 'order' object with an on_change
res = order_obj.product_id_change([order.id], ARGS AND/OR KWARGS...)
for k, v in res.get('value', {}).iteritems():
    setattr(order, k, v)
# 'order' object is now updated

The same, with a reusable function:

def on_change(oerp, obj, method, *args):
    """Update `obj` with the result of the on_change `method`"""
    res = oerp.execute(obj.__osv__['name'], method, *args)
    for k, v in res['value'].iteritems():
        setattr(obj, k, v)
    return obj

order = order_obj.browse(1)
order = on_change(oerp, order, 'product_id_change', ARGS...)

I have not tested the above code, but it should be ok.
It is not integrated to OERPLib, but it is short, and in Python ;)

Revision history for this message
Manu (manu-tiedra) said :


thank you very much for your fast and detailed response! I really appreciate it.

I was asking this because I saw some view stuff in the commits, but it seemed incomplete. Keep on the good work!

I'll do what you suggest. However, that means that I have to know in advance what on_change will fire on an object and that may depend on the installed modules. Anyway, just for using python alone it is worth the price.

Best regards,

Revision history for this message
Manu (manu-tiedra) said :

Thanks Sébastien Alix, that solved my question.

Revision history for this message
Sébastien Alix (sebastien-alix) said :


If it helps, there is a new service named 'inspect' currently developped, and I just added a method to list on_change methods with some info. For instance:

>>> oerp.inspect.list_on_change(['sale.order'])

Will produce a result like that: http://pastebin.com/nGS247aR
('sale.order.line' appears because this is the 'sale.order' form which set the related 'on_change')


Revision history for this message
Manu (manu-tiedra) said :


It does indeed help a lot.

Thank you very much!