Convert instances in RPC call result for on_change_with on field
Since d142b33fa3ab0fe5af25957f90ee77fe7eee51b3 the on_change_with method can return instances. Closes #12217
This commit is contained in:
1 parent
e444814cf7
commit
e74fe80df9
1 file changed
+16
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user