From 66e43af468ca68fc0213b498c5537dcf7bfbe791 Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Wed, 15 Nov 2023 11:02:05 +0000 Subject: [PATCH] [FIX] web_tour: tours should override with the saveAs option Steps to reproduce ================== - Enable the debug mode - Use an odoo instance with the design-themes - Click on the debug menu - Click on Start tour `OwlError: Got duplicate key in t-foreach: homepage` Cause of the issue ================== Website theme tours are registered here : https://github.com/odoo/odoo/blob/5c01439cf20b2c0ca08d618df6f249617127e6d1/addons/website/static/src/js/tours/tour_utils.js#L348-L358 The saveAs option is used but since the owl refactor, it doesn't override the previous tour. There is a default homepage tour in the website addon and then one for each theme. There should only be one available at a time (same as in 16.2). When selecting a new theme, the action button_choose_theme is called and that ensures that only one theme can be installed at the same time. opw-3595512 closes odoo/odoo#142350 X-original-commit: 69a361681c909cee5bf73a588dd4263bd49f1d5a Related: odoo/design-themes#745 Signed-off-by: Francois Georis (fge) Signed-off-by: Hubert Van De Walle Signed-off-by: Quentin Smetz (qsm) --- .../static/src/tour_service/tour_service.js | 3 ++- .../web_tour/static/tests/tour_service_tests.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/web_tour/static/src/tour_service/tour_service.js b/addons/web_tour/static/src/tour_service/tour_service.js index 6522094400b..043da2e3681 100644 --- a/addons/web_tour/static/src/tour_service/tour_service.js +++ b/addons/web_tour/static/src/tour_service/tour_service.js @@ -63,8 +63,9 @@ export const tourService = { const tours = {}; const tourRegistry = registry.category("web_tour.tours"); function register(name, tour) { + name = tour.saveAs || name tours[name] = { - name: tour.saveAs || name, + name, get steps() { if (typeof tour.steps === "function") { return tour.steps().map((step) => { diff --git a/addons/web_tour/static/tests/tour_service_tests.js b/addons/web_tour/static/tests/tour_service_tests.js index 8543ec3b066..14f71df54f6 100644 --- a/addons/web_tour/static/tests/tour_service_tests.js +++ b/addons/web_tour/static/tests/tour_service_tests.js @@ -101,6 +101,23 @@ QUnit.module("Tour service", (hooks) => { assert.strictEqual(sortedTours[0].name, "Tour 3"); }); + QUnit.test("override existing tour by using saveAs", async function (assert) { + registry.category("web_tour.tours") + .add("Tour 1", { + steps: () => [{ trigger: "#1" }], + saveAs: "homepage" + }) + .add("Tour 2", { + steps: () => [{ trigger: "#2" }], + saveAs: "homepage" + }); + const env = await makeTestEnv({}); + const sortedTours = env.services.tour_service.getSortedTours(); + assert.strictEqual(sortedTours.length, 1); + assert.deepEqual(sortedTours[0].steps, [{ shadow_dom: undefined, trigger: "#2" }]); + assert.deepEqual(sortedTours[0].name, "homepage"); + }); + QUnit.test("points to next step", async function (assert) { registry.category("web_tour.tours").add("tour1", { sequence: 10,