From 059ad64cea6758099f49b51ec2f9281174d12e0a Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 9 Sep 2016 11:08:49 +0200 Subject: [PATCH] [FIX] web_tour: clear inconsistent localstorage keys When users switch from one version to another, the localstorage is not cleared and users can get errors because the tour manager is trying to load steps (according to the localstorage content) which could not exist anymore. This could also happen when a module which extends another module tour is installed. --- addons/web_tour/static/src/js/tour_manager.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/web_tour/static/src/js/tour_manager.js b/addons/web_tour/static/src/js/tour_manager.js index 1d895959f51..61c5b11dc7c 100644 --- a/addons/web_tour/static/src/js/tour_manager.js +++ b/addons/web_tour/static/src/js/tour_manager.js @@ -243,15 +243,22 @@ return core.Class.extend({ _register: function (do_update, tour, name) { if (tour.ready) return $.when(); + var tour_is_consumed = _.contains(this.consumed_tours, name); + return tour.wait_for.then((function () { tour.current_step = parseInt(local_storage.getItem(get_step_key(name))) || 0; tour.steps = _.filter(tour.steps, (function (step) { return !step.edition || step.edition === this.edition; }).bind(this)); + if (tour_is_consumed || tour.current_step >= tour.steps.length) { + local_storage.removeItem(get_step_key(name)); + tour.current_step = 0; + } + tour.ready = true; - if (do_update && (this.running_tour === name || (!this.running_tour && !tour.test && !_.contains(this.consumed_tours, name)))) { + if (do_update && (this.running_tour === name || (!this.running_tour && !tour.test && !tour_is_consumed))) { this._to_next_step(name, 0); this.update(name); }