Files
tryton/trytond/tests/field_function.py
T
Cédric Krier fc66c17eb0 Call getter function when accessing Function field
If the record is unsaved and the getter is based on on_change_with, we can call
the getter to compute the value.
This value must not be stored in the cache as it may change prior to saving.

issue4193
issue9263
review317291002
2020-05-03 14:34:44 +02:00

33 lines
926 B
Python

# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelSQL, fields
from trytond.pool import Pool
class FunctionAccessor(ModelSQL):
"Function Accessor"
__name__ = 'test.function.accessor'
target = fields.Many2One('test.function.accessor.target', "Target")
function = fields.Function(
fields.Many2One('test.function.accessor.target', "Function"),
'on_change_with_function')
@fields.depends('target')
def on_change_with_function(self, name=None):
if self.target:
return self.target.id
class FunctionAccessorTarget(ModelSQL):
"Function Accessor Target"
__name__ = 'test.function.accessor.target'
def register(module):
Pool.register(
FunctionAccessor,
FunctionAccessorTarget,
module=module, type_='model')