diff --git a/sao/src/view/form.js b/sao/src/view/form.js index e3267f90be..124f22a0a7 100644 --- a/sao/src/view/form.js +++ b/sao/src/view/form.js @@ -2928,6 +2928,7 @@ function eval_pyson(value){ screen.current_record = screen.group.get(m2o_id); new Sao.Window.Form(screen, callback, { save_current: true, + prev_view: null, }); }); return; @@ -2998,6 +2999,7 @@ function eval_pyson(value){ new_: true, save_current: true, defaults: defaults, + prev_view: null, }); }); }, diff --git a/sao/src/window.js b/sao/src/window.js index e71a53e863..64c1cd28d4 100644 --- a/sao/src/window.js +++ b/sao/src/window.js @@ -162,7 +162,12 @@ return label; }); - this.prev_view = screen.current_view; + // prev_view should stay null + if (kwargs.prev_view !== undefined) { + this.prev_view = kwargs.prev_view; + } else { + this.prev_view = screen.current_view; + } this.screen.screen_container.alternate_view = true; this.info_bar = new Sao.Window.InfoBar(); var view_type = kwargs.view_type || 'form'; diff --git a/tryton/tryton/gui/window/attachment.py b/tryton/tryton/gui/window/attachment.py index b786e616a8..08351aa7fb 100644 --- a/tryton/tryton/gui/window/attachment.py +++ b/tryton/tryton/gui/window/attachment.py @@ -28,8 +28,9 @@ class Attachment(WinForm): ], mode=['tree', 'form'], readonly=not access['write']) - super().__init__(screen, self.callback, - view_type='tree', title=title) + super().__init__( + screen, self.callback, view_type='tree', title=title, + prev_view=screen.current_view) screen.search_filter() def destroy(self): diff --git a/tryton/tryton/gui/window/log.py b/tryton/tryton/gui/window/log.py index 1e0700dbdf..1ce2869fa4 100644 --- a/tryton/tryton/gui/window/log.py +++ b/tryton/tryton/gui/window/log.py @@ -110,7 +110,9 @@ class Log(WinForm): screen = Screen('ir.model.log', domain=[ ('resource', '=', self.resource), ], mode=['tree', 'form']) - super().__init__(screen, view_type='tree', title=title) + super().__init__( + screen, view_type='tree', title=title, + prev_view=screen.current_view) screen.search_filter() self.win.vbox.pack_start(grid, expand=False, fill=True, padding=0) diff --git a/tryton/tryton/gui/window/note.py b/tryton/tryton/gui/window/note.py index 0893ea718b..27cc29ce2e 100644 --- a/tryton/tryton/gui/window/note.py +++ b/tryton/tryton/gui/window/note.py @@ -18,8 +18,9 @@ class Note(WinForm): screen = Screen('ir.note', domain=[ ('resource', '=', self.resource), ], mode=['tree', 'form']) - super().__init__(screen, self.callback, view_type='tree', - title=title) + super().__init__( + screen, self.callback, view_type='tree', title=title, + prev_view=screen.current_view) screen.search_filter() def destroy(self): diff --git a/tryton/tryton/gui/window/view_board/action.py b/tryton/tryton/gui/window/view_board/action.py index 47ea7147f2..ae4917dcfa 100644 --- a/tryton/tryton/gui/window/view_board/action.py +++ b/tryton/tryton/gui/window/view_board/action.py @@ -120,7 +120,9 @@ class Action: self.screen.current_record.save() else: self.screen.current_record.cancel() - WinForm(self.screen, callback, title=self.title.get_text()) + WinForm( + self.screen, callback, title=self.title.get_text(), + prev_view=self.screen.current_view) def display(self): self.screen.search_filter(self.screen.screen_container.get_text()) diff --git a/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py index e2752072ed..111a8f8c04 100644 --- a/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -284,7 +284,8 @@ class Many2Many(Widget): # Force a display to clear the CellCache self.screen.display() self._popup = False - WinForm(screen, callback, save_current=True) + WinForm( + screen, callback, save_current=True, prev_view=screen.current_view) def _sig_new(self, defaults=None): if self._popup: @@ -304,7 +305,8 @@ class Many2Many(Widget): self._popup = False WinForm( - screen, callback, new=True, save_current=True, defaults=defaults) + screen, callback, new=True, save_current=True, defaults=defaults, + prev_view=screen.current_view) def _readonly_set(self, value): super()._readonly_set(value) diff --git a/tryton/tryton/gui/window/view_form/view/form_gtk/many2one.py b/tryton/tryton/gui/window/view_form/view/form_gtk/many2one.py index 9ae8b16d1b..8c0dda1d2c 100644 --- a/tryton/tryton/gui/window/view_form/view/form_gtk/many2one.py +++ b/tryton/tryton/gui/window/view_form/view/form_gtk/many2one.py @@ -186,7 +186,8 @@ class Many2One(Widget): screen.current_record.rec_name())) self._popup = False WinForm( - screen, callback, new=True, save_current=True, defaults=defaults) + screen, callback, new=True, save_current=True, defaults=defaults, + prev_view=None) def sig_edit(self, entry=None, icon_pos=None, *args): if entry: @@ -225,7 +226,7 @@ class Many2One(Widget): force_change=True) self._popup = False self.changed = True - WinForm(screen, callback, save_current=True) + WinForm(screen, callback, save_current=True, prev_view=None) return if not self._readonly: domain = self.field.domain_get(self.record) diff --git a/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py index 826797186a..dd389231e8 100644 --- a/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -398,7 +398,8 @@ class One2Many(Widget): field_size -= len(self.field.get_eval(self.record)) + 1 WinForm( self.screen, lambda a: update_sequence(), new=True, - defaults=defaults, many=field_size) + defaults=defaults, many=field_size, + prev_view=self.screen.current_view) def _new_product(self, defaults=None): fields = self.attrs['product'].split(',') @@ -472,7 +473,7 @@ class One2Many(Widget): def callback(result): self._popup = False - WinForm(self.screen, callback) + WinForm(self.screen, callback, prev_view=self.screen.current_view) def _sig_next(self, widget): if not self._validate(): diff --git a/tryton/tryton/gui/window/view_form/view/list_gtk/widget.py b/tryton/tryton/gui/window/view_form/view/list_gtk/widget.py index a236890a75..46ce5baca3 100644 --- a/tryton/tryton/gui/window/view_form/view/list_gtk/widget.py +++ b/tryton/tryton/gui/window/view_form/view/list_gtk/widget.py @@ -974,13 +974,15 @@ class M2O(GenericText): if target_id and target_id >= 0: screen.load([target_id]) screen.current_record = screen.group.get(target_id) - WinForm(screen, open_callback, save_current=True) + WinForm( + screen, open_callback, save_current=True, + prev_view=screen.current_view) else: defaults = defaults.copy() if defaults is not None else {} defaults['rec_name'] = text WinForm( screen, open_callback, new=True, save_current=True, - defaults=defaults) + defaults=defaults, prev_view=screen.current_view) def search_remote(self, record, field, text, callback=None): model = self.get_model(record, field) @@ -1127,7 +1129,9 @@ class O2M(GenericText): def open_callback(result): if callback: callback() - WinForm(screen, open_callback, view_type='tree', context=context) + WinForm( + screen, open_callback, view_type='tree', context=context, + prev_view=screen.current_view) class M2M(O2M): @@ -1154,8 +1158,9 @@ class M2M(O2M): def open_callback(result): if callback: callback() - WinForm(screen, open_callback, view_type='tree', domain=domain, - context=context) + WinForm( + screen, open_callback, view_type='tree', domain=domain, + context=context, prev_view=screen.current_view) class Selection(GenericText, SelectionMixin, PopdownMixin): diff --git a/tryton/tryton/gui/window/win_form.py b/tryton/tryton/gui/window/win_form.py index dd70a0bc92..a5252960d4 100644 --- a/tryton/tryton/gui/window/win_form.py +++ b/tryton/tryton/gui/window/win_form.py @@ -16,6 +16,7 @@ from tryton.gui.window.nomodal import NoModal from .infobar import InfoBar _ = gettext.gettext +SENTINEL = object() class WinForm(NoModal, InfoBar): @@ -23,7 +24,7 @@ class WinForm(NoModal, InfoBar): def __init__(self, screen, callback=None, view_type='form', new=False, many=0, domain=None, context=None, - save_current=False, title='', defaults=None): + save_current=False, title='', defaults=None, prev_view=SENTINEL): tooltips = common.Tooltips() NoModal.__init__(self) @@ -49,7 +50,10 @@ class WinForm(NoModal, InfoBar): if not title: title = MODELNAME.get(screen.model_name) self.title = title - self.prev_view = self.screen.current_view + if prev_view is not SENTINEL: + self.prev_view = prev_view + else: + self.prev_view = screen.current_view self.screen.screen_container.alternate_view = True self.screen.switch_view(view_type=view_type) if self.screen.current_view.view_type != view_type: @@ -519,7 +523,8 @@ class WinForm(NoModal, InfoBar): viewport = self.screen.screen_container.alternate_viewport if viewport and viewport.get_parent(): viewport.get_parent().remove(viewport) - self.screen.switch_view(view_type=self.prev_view.view_type) + if self.prev_view: + self.screen.switch_view(view_type=self.prev_view.view_type) if getattr(self, 'win', None): self.win.destroy() NoModal.destroy(self) diff --git a/tryton/tryton/gui/window/win_search.py b/tryton/tryton/gui/window/win_search.py index 80c9e9abe7..ed62999f9b 100644 --- a/tryton/tryton/gui/window/win_search.py +++ b/tryton/tryton/gui/window/win_search.py @@ -167,7 +167,9 @@ class WinSearch(NoModal): else: self.callback(None) self.destroy() - WinForm(screen, callback, new=True, save_current=True) + WinForm( + screen, callback, new=True, save_current=True, + prev_view=screen.current_view) return if res: group = self.screen.group