diff --git a/tryton/common/selection.py b/tryton/common/selection.py index eb0bfa03e4..e7b79472bf 100644 --- a/tryton/common/selection.py +++ b/tryton/common/selection.py @@ -11,6 +11,7 @@ class SelectionMixin(object): def __init__(self, *args, **kwargs): super(SelectionMixin, self).__init__(*args, **kwargs) self.selection = None + self.inactive_selection = [] self._last_domain = None self._values2selection = {} self._domain_cache = {} @@ -36,6 +37,7 @@ class SelectionMixin(object): if self.attrs.get('sort', True): selection.sort(key=operator.itemgetter(1)) self.selection = selection[:] + self.inactive_selection = [] def update_selection(self, record, field): if not field: @@ -71,6 +73,23 @@ class SelectionMixin(object): selection = [] self._last_domain = None self.selection = selection[:] + self.inactive_selection = [] + + def get_inactive_selection(self, value): + if 'relation' not in self.attrs: + return '' + for val, text in self.inactive_selection: + if str(val) == str(value): + return text + else: + try: + result, = RPCExecute('model', self.attrs['relation'], 'read', + [value], ['rec_name']) + self.inactive_selection.append((result['id'], + result['rec_name'])) + return result['rec_name'] + except RPCException: + return '' def selection_shortcuts(entry): diff --git a/tryton/gui/window/view_form/view/form_gtk/selection.py b/tryton/gui/window/view_form/view/form_gtk/selection.py index 113c48ca14..8eb24f44e7 100644 --- a/tryton/gui/window/view_form/view/form_gtk/selection.py +++ b/tryton/gui/window/view_form/view/form_gtk/selection.py @@ -100,6 +100,11 @@ class Selection(WidgetInterface, SelectionMixin, PopdownMixin): value = val if len(txt) == len(text): break + if not value: + for val, txt in self.inactive_selection: + if txt == text: + value = val + break return value def sig_key_press(self, widget, event): @@ -154,5 +159,10 @@ class Selection(WidgetInterface, SelectionMixin, PopdownMixin): child.set_text(long_text) found = True break + if not found: + text = self.get_inactive_selection(value) + if text: + child.set_text(text) + found = True if not found: child.set_text('') diff --git a/tryton/gui/window/view_form/view/list_gtk/parser.py b/tryton/gui/window/view_form/view/list_gtk/parser.py index 163e3a0e59..847f780e49 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -915,7 +915,10 @@ class Selection(Char, SelectionMixin): field = record[self.field_name] self.update_selection(record, field) value = record[self.field_name].get(record) - return dict(self.selection).get(value, '') + text = dict(self.selection).get(value, '') + if value and not text: + text = self.get_inactive_selection(value) + return text def value_from_text(self, record, text, callback=None): field = record[self.field_name]