Reviewers: ,


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

Affected files:
  M tryton/gui/window/view_form/screen/screen.py
  M tryton/gui/window/view_form/view/form_gtk/one2many.py


Index: tryton/gui/window/view_form/screen/screen.py
===================================================================

--- a/tryton/gui/window/view_form/screen/screen.py
+++ b/tryton/gui/window/view_form/screen/screen.py
@@ -677,8 +677,6 @@
             if (self.current_record
                     and self.current_record in self.current_record.group):
                 pass
-            elif self.group:
-                self.current_record = self.group[0]
             else:
                 self.current_record = None
         if self.views:

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
@@ -172,7 +172,8 @@
         frame = gtk.Frame()
         frame.add(hbox)
         frame.set_shadow_type(gtk.SHADOW_OUT)
-        self.widget.pack_start(frame, expand=False, fill=True)
+        if not self.attrs.get('group') or self.attrs.get('mode') != 'form':
+            self.widget.pack_start(frame, expand=False, fill=True)

         self.screen = Screen(attrs['relation'],
             mode=attrs.get('mode', 'tree,form').split(','),
@@ -439,7 +440,19 @@
     def group_sync(self, screen):
         if not self.view or not self.view.widgets:
             return
+        if (screen.current_view.view_type == 'form'
+                and (screen.current_record is None
+                    or (screen.group.root_group.model_name
+                        != screen.current_record.model_name))):
+            return
+
+        def is_compatbile(screen, record):
+            return not (screen.current_view.view_type == 'form'
+                and record is not None
+                and screen.model_name != record.model_name)
+
         current_record = self.screen.current_record
+        to_sync = []
         for widget in self.view.widgets[self.field_name]:
             if (widget == self
                     or widget.attrs.get('group') != self.attrs['group']
@@ -447,14 +460,22 @@
                 continue
             if widget.screen.current_record == current_record:
                 continue
+            record = current_record
+            if not is_compatbile(widget.screen, record):
+                record = None
             if not widget._validate():
                 def go_previous():
-                    screen.current_record = widget.screen.current_record
+                    record = widget.screen.current_record
+                    if not is_compatbile(screen, record):
+                        record = None
+                    screen.current_record = record
                     screen.display()
                 gobject.idle_add(go_previous)
-                break
-            widget.screen.current_record = current_record
-            widget.screen.display()
+                return
+            to_sync.append((widget, record))
+        for widget, record in to_sync:
+            widget.screen.current_record = record
+            widget.display(widget.record, widget.field)

     def display(self, record, field):
         super(One2Many, self).display(record, field)
@@ -468,8 +489,10 @@
             self.screen.display()
             return False
         new_group = field.get_client(record)
-
-        if id(self.screen.group) != id(new_group):
+        if self.attrs.get('group') and self.attrs.get('mode') == 'form':
+            if self.screen.current_record is None:
+                self.invisible_set(True)
+        elif id(self.screen.group) != id(new_group):
             self.screen.group = new_group
             if (self.screen.current_view.view_type == 'tree') \
                     and self.screen.editable_get():
@@ -487,6 +510,9 @@
         return True

     def set_value(self, record, field):
+        if (self.screen.current_view.view_type == 'form'
+                and self.screen.model_name != record.model_name):
+            return True
         self.screen.save_tree_state()
         self.screen.current_view.set_value()
         if self.screen.modified():  # TODO check if required



Reply via email to