Reviewers: ,


Please review this at http://codereview.tryton.org/250002/

Affected files:
  M tryton/gui/window/view_form/model/record.py
  M tryton/gui/window/view_form/view/form_gtk/many2many.py
  M tryton/gui/window/view_form/view/form_gtk/many2one.py
  M tryton/gui/window/view_form/view/form_gtk/one2many.py
  M tryton/gui/window/view_form/view/list_gtk/parser.py
  M tryton/gui/window/win_form.py
  M tryton/gui/window/win_search.py


Index: tryton/gui/window/view_form/model/record.py
===================================================================

--- a/tryton/gui/window/view_form/model/record.py
+++ b/tryton/gui/window/view_form/model/record.py
@@ -91,6 +91,8 @@
             fnames.extend(('%s.rec_name' % fname for fname in fnames[:]
                     if self.group.fields[fname].attrs['type']
                     in ('many2one', 'one2one', 'reference')))
+            if 'rec_name' not in fnames:
+                fnames.append('rec_name')
             fnames.append('_timestamp')
             ctx = rpc.CONTEXT.copy()
             ctx.update(record_context)
@@ -428,6 +430,8 @@
                 self._timestamp = value
                 continue
             if fieldname not in self.group.fields:
+                if fieldname == 'rec_name':
+                    self.value['rec_name'] = value
                 continue
             if isinstance(self.group.fields[fieldname], fields.O2MField):
                 later[fieldname] = value

Index: tryton/gui/window/view_form/view/form_gtk/many2many.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/many2many.py
+++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py
@@ -140,10 +140,10 @@
             self.focus_out = True
             return False

-        def callback(ids):
+        def callback(result):
             res_id = None
-            if ids:
-                res_id = ids[0]
+            if result:
+                res_id, _ = result[0]
             self.focus_out = True
             self.screen.load(ids, modified=True)
             self.screen.display(res_id=res_id)
@@ -155,7 +155,7 @@
                 view_ids=self.attrs.get('view_ids', '').split(','),
                 views_preload=self.attrs.get('views', {}))
         else:
-            callback(ids)
+            callback([(i, None) for i in ids])

     def _sig_remove(self, *args):
         self.screen.remove(remove=True)

Index: tryton/gui/window/view_form/view/form_gtk/many2one.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/many2one.py
+++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py
@@ -150,10 +150,10 @@
                     self.changed = True
                     return

-                def callback(ids):
-                    if ids:
+                def callback(result):
+                    if result:
                         self.field.set_client(self.record,
-                            self.value_from_id(ids[0]), force_change=True)
+ self.value_from_id(*result[0]), force_change=True)
                     self.focus_out = True
                     self.display(self.record, self.field)
                     self.changed = True
@@ -241,10 +241,10 @@
                 self.display(self.record, self.field)
                 return True

-            def callback(ids):
-                if ids:
+            def callback(result):
+                if result:
                     self.field.set_client(self.record,
-                        self.value_from_id(ids[0]), force_change=True)
+                        self.value_from_id(*result[0]), force_change=True)
                 self.focus_out = True
                 self.display(self.record, self.field)
                 self.changed = True

Index: tryton/gui/window/view_form/view/form_gtk/one2many.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/one2many.py
+++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py
@@ -322,10 +322,10 @@
             common.process_exception(exception)
             return False

-        def callback(ids):
+        def callback(result):
             res_id = None
-            if ids:
-                res_id = ids[0]
+            if result:
+                res_id, = result[0]
             self.screen.load(ids, modified=True)
             self.screen.display(res_id=res_id)
             self.screen.set_cursor()
@@ -336,7 +336,7 @@
                 view_ids=self.attrs.get('view_ids', '').split(','),
                 views_preload=self.attrs.get('views', {}))
         else:
-            callback(ids)
+            callback([(i, None) for i in ids])

     def _sig_label(self, screen, signal_data):
         name = '_'

Index: tryton/gui/window/view_form/view/list_gtk/parser.py
===================================================================

--- a/tryton/gui/window/view_form/view/list_gtk/parser.py
+++ b/tryton/gui/window/view_form/view/list_gtk/parser.py
@@ -658,14 +658,7 @@
         def search_callback(found):
             value = None
             if found:
-                args = ('model', relation, 'read', found[0], ['rec_name'],
-                        context)
-                try:
-                    res = rpc.execute(*args)
-                except TrytonServerError, exception:
-                    res = common.process_exception(exception, *args)
-                if res:
-                    value = (found[0], res['rec_name'])
+                value = found[0]
             field.set_client(record, value)
             if callback:
                 callback()
@@ -760,7 +753,11 @@
             return

         def winsearch_callback(result):
-            field.set_client(record, result or [])
+            if result:
+                result = [i for i, _ in result]
+            else:
+                result = []
+            field.set_client(record, result)
             if callback:
                 callback()
         WinSearch(relation, winsearch_callback, sel_multi=True, ids=ids,
@@ -795,7 +792,7 @@

         def open_callback(result):
             if result:
-                field.set_client(record, result)
+                field.set_client(record, [i for i, _ in result])
             if callback:
                 callback()
         WinSearch(relation, open_callback, sel_multi=True, ids=ids,

Index: tryton/gui/window/win_form.py
===================================================================

--- a/tryton/gui/window/win_form.py
+++ b/tryton/gui/window/win_form.py
@@ -270,10 +270,10 @@
             common.process_exception(exception)
             return False

-        def callback(ids):
+        def callback(result):
             res_id = None
-            if ids:
-                res_id = ids[0]
+            if result:
+                res_id, _ = result[0]
             self.screen.load(ids, modified=True)
             self.screen.display(res_id=res_id)
             self.screen.set_cursor()

Index: tryton/gui/window/win_search.py
===================================================================

--- a/tryton/gui/window/win_search.py
+++ b/tryton/gui/window/win_search.py
@@ -121,10 +121,15 @@

             def callback(result):
                 if result and screen.save_current():
-                    res = [screen.current_record.id]
+                    record = screen.current_record
+                    res = [(record.id, record.value.get('rec_name', ''))]
                     self.destroy()
                     self.callback(res)
             WinForm(screen, callback, new=True)
             return
+        if res:
+            group = self.screen.group
+            res = [(id_, group.get(id_).value.get('rec_name', ''))
+                for id_ in res]
         self.destroy()
         return self.callback(res)



--
[email protected] mailing list

Reply via email to