Reviewers: ,


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

Affected files:
  M tryton/gui/window/attachment.py
  M tryton/gui/window/form.py
  M tryton/gui/window/view_form/view/list.py


Index: tryton/gui/window/attachment.py
===================================================================
--- a/tryton/gui/window/attachment.py
+++ b/tryton/gui/window/attachment.py
@@ -5,20 +5,27 @@
 from tryton.gui.window.win_form import WinForm


-class Attachment(object):
+class Attachment(WinForm):
     "Attachment window"

-    def __init__(self, model_name, record_id):
+    def __init__(self, model_name, record_id, callback=None):
         self.resource = '%s,%s' % (model_name, record_id)
-
-    def run(self):
+        self.attachment_callback = callback
         screen = Screen('ir.attachment', domain=[
             ('resource', '=', self.resource),
             ], mode=['tree', 'form'], context={
                 'resource': self.resource,
             }, exclude_field='resource')
         screen.search_filter()
-        def callback(result):
-            if result:
-                screen.group.save()
-        WinForm(screen, callback, view_type='tree')
+        super(Attachment, self).__init__(screen, self.callback,
+            view_type='tree')
+
+    def destroy(self):
+        self.prev_view.save_width_height()
+        super(Attachment, self).destroy()
+
+    def callback(self, result):
+        if result:
+            self.screen.group.save()
+        if self.attachment_callback:
+            self.attachment_callback()
Index: tryton/gui/window/form.py
===================================================================
--- a/tryton/gui/window/form.py
+++ b/tryton/gui/window/form.py
@@ -240,7 +240,9 @@
     def sig_attach(self, widget=None):
         obj_id = self.id_get()
         if obj_id >= 0 and obj_id is not False:
-            Attachment(self.model, obj_id).run()
+            def callback():
+                self.update_attachment_count(reload=True)
+            Attachment(self.model, obj_id, callback)
         else:
             self.message_info(_('No record selected!'))
         self.update_attachment_count(reload=True)
@@ -482,6 +484,7 @@
         self.activate_save()

     def modified_save(self, reload=True):
+        self.screen.current_view.set_value()
         if self.screen.modified():
             value = sur_3b(
                     _('This record has been modified\n' \
Index: tryton/gui/window/view_form/view/list.py
===================================================================
--- a/tryton/gui/window/view_form/view/list.py
+++ b/tryton/gui/window/view_form/view/list.py
@@ -634,28 +634,32 @@
     def __getitem__(self, name):
         return None

+    def save_width_height(self):
+        if not CONFIG['client.save_width_height']:
+            return
+        fields = {}
+        last_col = None
+        for col in self.widget_tree.get_columns():
+            if col.get_visible():
+                last_col = col
+            if not hasattr(col, 'name') or not hasattr(col, 'width'):
+                continue
+            if col.get_width() != col.width and col.get_visible():
+                fields[col.name] = col.get_width()
+        #Don't set width for last visible columns
+        #as it depends of the screen size
+        if last_col and last_col.name in fields:
+            del fields[last_col.name]
+
+        if fields and any(fields.itervalues()):
+            try:
+                rpc.execute('model', 'ir.ui.view_tree_width', 'set_width',
+                        self.screen.model_name, fields, rpc.CONTEXT)
+            except TrytonServerError:
+                pass
+
     def destroy(self):
-        if CONFIG['client.save_width_height']:
-            fields = {}
-            last_col = None
-            for col in self.widget_tree.get_columns():
-                if col.get_visible():
-                    last_col = col
-                if not hasattr(col, 'name') or not hasattr(col, 'width'):
-                    continue
-                if col.get_width() != col.width and col.get_visible():
-                    fields[col.name] = col.get_width()
-            #Don't set width for last visible columns
-            #as it depends of the screen size
-            if last_col and last_col.name in fields:
-                del fields[last_col.name]
-
-            if fields and any(fields.itervalues()):
-                try:
- rpc.execute('model', 'ir.ui.view_tree_width', 'set_width',
-                            self.screen.model_name, fields, rpc.CONTEXT)
-                except TrytonServerError:
-                    pass
+        self.save_width_height()
         self.widget_tree.destroy()
         self.screen = None
         self.widget_tree = None


--
[email protected] mailing list

Reply via email to