From b5479332d9a90076e54d0470dcd3ccdd4300094c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 3 Nov 2015 12:20:49 +0100 Subject: [PATCH] Use instance context in translated descriptor of Selection field It is more expected from the translated descriptor to return translation in the language from the instance instead of the current context. issue5028 review15701002 --- CHANGELOG | 2 ++ doc/ref/models/fields.rst | 3 ++- trytond/model/fields/selection.py | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) 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 == '':