diff --git a/CHANGELOG b/CHANGELOG index 14105d6b69..d04a879f56 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Use instance context in translated descriptor of Selection + Version 3.8.0 - 2015-11-02 * Bug fixes (see mercurial logs for details) * Add test for all field methods diff --git a/doc/ref/models/fields.rst b/doc/ref/models/fields.rst index 032603ea35..1f9acd2915 100644 --- a/doc/ref/models/fields.rst +++ b/doc/ref/models/fields.rst @@ -439,7 +439,8 @@ Instance methods: .. method:: Selection.translated([name]) Returns a descriptor for the translated value of the field. The descriptor - must be used on the same class as the field. + must be used on the same class as the field. It will use the language + defined in the context of the instance accessed. Reference --------- diff --git a/trytond/model/fields/selection.py b/trytond/model/fields/selection.py index bd29efed92..92221f4427 100644 --- a/trytond/model/fields/selection.py +++ b/trytond/model/fields/selection.py @@ -5,6 +5,7 @@ import warnings from sql.conditionals import Case from ... import backend +from ...transaction import Transaction from .field import Field, SQLType @@ -82,7 +83,9 @@ class TranslatedSelection(object): def __get__(self, inst, cls): if inst is None: return self - selection = dict(cls.fields_get([self.name])[self.name]['selection']) + with Transaction().set_context(getattr(inst, '_context', {})): + selection = dict( + cls.fields_get([self.name])[self.name]['selection']) value = getattr(inst, self.name) # None and '' are equivalent if value is None or value == '':