diff --git a/trytond/model/fields/selection.py b/trytond/model/fields/selection.py index 92221f4427..976dbf2998 100644 --- a/trytond/model/fields/selection.py +++ b/trytond/model/fields/selection.py @@ -6,6 +6,7 @@ from sql.conditionals import Case from ... import backend from ...transaction import Transaction +from ...tools import is_instance_method from .field import Field, SQLType @@ -84,8 +85,14 @@ class TranslatedSelection(object): if inst is None: return self with Transaction().set_context(getattr(inst, '_context', {})): - selection = dict( - cls.fields_get([self.name])[self.name]['selection']) + selection = cls.fields_get([self.name])[self.name]['selection'] + if not isinstance(selection, (tuple, list)): + sel_func = getattr(cls, selection) + if not is_instance_method(cls, selection): + selection = sel_func() + else: + selection = sel_func(inst) + selection = dict(selection) value = getattr(inst, self.name) # None and '' are equivalent if value is None or value == '': diff --git a/trytond/tests/test.py b/trytond/tests/test.py index b7e9e3beec..68c8b9ef8e 100644 --- a/trytond/tests/test.py +++ b/trytond/tests/test.py @@ -654,8 +654,11 @@ class Selection(ModelSQL): select_string = select.translated('select') dyn_select = fields.Selection('get_selection', 'Instance Dynamic Selection') + dyn_select_string = dyn_select.translated('dyn_select') dyn_select_static = fields.Selection('static_selection', 'Static Selection') + dyn_select_static_string = dyn_select_static.translated( + 'dyn_select_static') @fields.depends('select') def get_selection(self): diff --git a/trytond/tests/test_fields.py b/trytond/tests/test_fields.py index e9e24cc9a7..a9e291ce00 100644 --- a/trytond/tests/test_fields.py +++ b/trytond/tests/test_fields.py @@ -3192,6 +3192,7 @@ class FieldsTestCase(unittest.TestCase): self.assert_(selection3) self.assertEqual(selection3.select, 'arabic') self.assertEqual(selection3.dyn_select, '1') + self.assertEqual(selection3.dyn_select_string, '1') selection4, = Selection.create( [{'select': 'hexa', 'dyn_select': '0x3'}]) @@ -3210,6 +3211,11 @@ class FieldsTestCase(unittest.TestCase): self.assertRaises(UserError, Selection.create, [{'select': 'hexa', 'dyn_select': '3'}]) + selection7, = Selection.create( + [{'dyn_select_static': '1'}]) + self.assertEqual(selection7.dyn_select_static, '1') + self.assertEqual(selection7.dyn_select_static_string, '1') + self.assertRaises(UserError, SelectionRequired.create, [{}]) transaction.rollback()