From 206cc91a63b614881a7902e048fce25805a0c374 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 15 Jan 2016 14:52:13 +0100 Subject: [PATCH] [FIX] web: view_manager: restore internal state on switch view failure When an error occured when switching from a view to another (e.g. switching to a form view for an id that doesn't exist, by editing the url), active_view and view_stack were updated even though the switch failed. The view manager thus lost the reference to the real current active view, which couldn't be detached anymore. This resulted in two views being displayed at the same time if the user kept navigating through this view manager. This is a backport of odoo/enterprise@0b1aafa6b and odoo/enterprise@8e691be. --- addons/web/static/src/js/view_manager.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_manager.js b/addons/web/static/src/js/view_manager.js index c5db4b954ca..e720db2475b 100644 --- a/addons/web/static/src/js/view_manager.js +++ b/addons/web/static/src/js/view_manager.js @@ -156,11 +156,20 @@ var ViewManager = Widget.extend(ControlPanelMixin, { self.searchview.do_search(); }); } - return $.when(view.created, this.active_search).then(function () { + var switched = $.when(view.created, this.active_search).then(function () { return self._display_view(view_options, old_view).then(function () { self.trigger('switch_mode', view_type, no_store, view_options); }); }); + switched.fail(function(e) { + if (!(e && e.code === 200 && e.data.exception_type)) { + self.do_warn(_t("Error"), view.controller.display_name + _t(" view couldn't be loaded")); + } + // Restore internal state + self.active_view = old_view; + self.view_stack.pop(); + }); + return switched; }, _display_view: function (view_options, old_view) { var self = this;