diff --git a/trytond/trytond/model/fields/field.py b/trytond/trytond/model/fields/field.py index 8f1c5bdead..f846e4c4aa 100644 --- a/trytond/trytond/model/fields/field.py +++ b/trytond/trytond/model/fields/field.py @@ -1,7 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import warnings -from functools import wraps +from functools import partial, wraps import sql from sql import ( @@ -195,6 +195,20 @@ def on_change_result(record): return record._changed_values +def on_change_with_result(field, value): + from ..modelstorage import ModelStorage + if field._type in {'many2one', 'one2one', 'reference'}: + if isinstance(value, ModelStorage): + if field._type == 'reference': + value = str(value) + else: + value = value.id + elif field._type in {'one2many', 'many2many'}: + if isinstance(value, (list, tuple)): + value = [int(r) for r in value] + return value + + def domain_method(func): @wraps(func) def wrapper(self, domain, tables, Model): @@ -455,7 +469,7 @@ class Field(object): def set_rpc(self, model): for attribute, result in ( ('on_change', on_change_result), - ('on_change_with', None), + ('on_change_with', partial(on_change_with_result, self)), ): if not getattr(self, attribute): continue