This patch makes the M2O fields display by the Selection widget update
the selection of terms available accordingly to the domain set on the
field.
Please review this at http://codereview.appspot.com/4253070/
Affected files:
M CHANGELOG
M tryton/gui/window/view_form/view/form_gtk/selection.py
Index: CHANGELOG
===================================================================
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Selection widget used for many2one dynamically change their content
following
+ the domain specification
* Fix warning in wizards
* Added possibility to use server-side icons
* Added additional gtk.Entry for filename on BinaryField
Index: tryton/gui/window/view_form/view/form_gtk/selection.py
===================================================================
--- a/tryton/gui/window/view_form/view/form_gtk/selection.py
+++ b/tryton/gui/window/view_form/view/form_gtk/selection.py
@@ -6,6 +6,7 @@
import tryton.rpc as rpc
import tryton.common as common
from tryton.pyson import PYSONDecoder
+from tryton.common import EvalEnvironment
class Selection(WidgetInterface):
@@ -32,15 +33,24 @@
self.widget.set_focus_chain([child])
self._selection = {}
- selection = attrs.get('selection', [])[:]
- self.selection = selection[:]
- if not attrs.get('domain'):
+ self.selection = attrs.get('selection', [])[:]
+ self.attrs = attrs
+ self.update_selection()
+ self.last_key = (None, 0)
+
+ def update_selection(self, record=None):
+ if record is None:
+ context = rpc.CONTEXT
+ else:
+ context = EvalEnvironment(record, False)
+ selection = self.attrs.get('selection', [])[:]
+ if not self.attrs.get('domain'):
domain = []
else:
- domain = PYSONDecoder(rpc.CONTEXT).decode(attrs.get('domain'))
- if 'relation' in attrs:
+ domain = PYSONDecoder(context).decode(self.attrs.get('domain'))
+ if 'relation' in self.attrs:
try:
- result = rpc.execute('model',
attrs['relation'], 'search_read',
+ result = rpc.execute('model',
self.attrs['relation'], 'search_read',
domain, 0, None, None, ['rec_name'], rpc.CONTEXT)
selection = [(x['id'], x['rec_name']) for x in result]
except Exception, exception:
@@ -69,10 +79,9 @@
for i in todel[::-1]:
del selection[i]
- if attrs.get('sort', True):
+ if self.attrs.get('sort', True):
selection.sort(lambda x, y: cmp(x[1], y[1]))
self.set_popdown(selection)
- self.last_key = (None, 0)
def grab_focus(self):
return self.entry.grab_focus()
@@ -140,6 +149,7 @@
super(Selection, self)._menu_sig_default_set(reset=reset)
def display(self, record, field):
+ self.update_selection(record)
child = self.entry.get_child()
self.changed = False
if not field:
--
[email protected] mailing list