Handle inactive records in M2O displayed as selection
review981002
This commit is contained in:
1 parent
327159b7ed
commit
afde3e8d72
3 files changed
+33
-1
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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('')
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user