20
21
################################################################################
23
from openerp.osv.orm import Model
24
from openerp.osv.osv import except_osv
24
25
from tools.translate import _
25
26
from openerp.tools.config import config
27
28
def call_onchange(self, cr, uid, onchange_name, vals, defaults=None, **kwargs):
29
Used in base_sale_multichannel in order to call onchange method on sale_order_line and sale_order
30
In order to call onchange you must have to create a function "_get_kwargs_my_onchange_name"
31
that will return the kwargs for your onchange
30
Used in base_sale_multichannel in order to call onchange method on sale_order_line and sale_order.
31
In order to call onchange, you must have to create a function "_get_kwargs_my_onchange_name"
32
that will return the kwargs for your onchange.
33
@param onchange_name: string that contain the onchange method to call
34
@param vals: dictionnary of value that have been filled for the object
34
@param onchange_name: string that contains the onchange method to call
35
@param vals: dictionnary of values that has been filled for the object
35
36
@param defaults: dictionnary of defaults values for the object
36
@return: dictionary of line updated with the value returned by the onchange
37
@return: dictionary of lines updated with the values returned by the onchange
40
41
vals_with_default = defaults.copy()
41
42
vals_with_default.update(vals)
43
kwargs2 = eval("self._get_kwargs_%s"%onchange_name)(cr, uid, vals_with_default, **kwargs)
44
args2, kwargs2 = getattr(self, "_get_params_%s" % onchange_name)(cr, uid, vals_with_default, **kwargs)
44
45
except Exception, e:
45
46
if config['debug_mode']: raise
46
raise osv.except_osv(_('On Change Player'), _("Error when trying to get the kwargs for the onchange %s on \
47
the object %s. Error message : %s" %(onchange_name, self._name, e)))
47
raise except_osv(_('On Change Player'),
48
_("Error when trying to get the params for the onchange %s on "
49
"the object %s. Error message : %s") % (onchange_name, self._name, e))
49
res = eval("self.%s"%onchange_name)(cr, uid, **kwargs2)
51
res = getattr(self, onchange_name)(cr, uid, *args2, **kwargs2)
50
52
for key in res['value']:
51
53
if not key in vals:
52
# If the value is false and the field is not a boolean we don't pass it as it useless
53
# If it's a problem for you please contact me sebastien.beau@akretion.com,
54
# because pass empty value will provoque some conflict with magentoerpconnect. Thanks
54
# If the value is false and the field is not a boolean, we don't pass it as it is useless
55
# If it's a problem for you, please contact me sebastien.beau@akretion.com,
56
# because passing empty value will trigger a conflict with magentoerpconnect. Thanks.
55
57
if res['value'][key] or self._columns[key]._type == 'bool':
56
58
vals[key] = res['value'][key]
57
59
except Exception, e:
58
60
if config['debug_mode']: raise
59
raise osv.except_osv(_('On Change Player'), _("Error when trying to playing the onchange %s on the object %s. \
60
Error message : %s" %(onchange_name, self._name, e)))
61
raise except_osv(_('On Change Player'),
62
_("Error when trying to play the onchange %s on the object %s. "
63
"Error message : %s") % (onchange_name, self._name, e))
63
osv.osv.call_onchange = call_onchange
66
Model.call_onchange = call_onchange