diff --git a/tryton/gui/window/attachment.py b/tryton/gui/window/attachment.py index 4c83734452..daafd69d77 100644 --- a/tryton/gui/window/attachment.py +++ b/tryton/gui/window/attachment.py @@ -5,20 +5,27 @@ from tryton.gui.window.view_form.screen import Screen 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() diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index 7e004fe4b6..28f053d583 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -240,7 +240,9 @@ class Form(SignalEvent, TabContent): 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) diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 30b4dee97e..7c39e0eea3 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -634,28 +634,32 @@ class ViewList(ParserView): def __getitem__(self, name): return None - 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] + 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 + 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): + self.save_width_height() self.widget_tree.destroy() self.screen = None self.widget_tree = None