From cb345ea1e781012175b28be277ea5c4f78f82558 Mon Sep 17 00:00:00 2001 From: "Maruan Aguerdouh (magm)" Date: Thu, 9 Mar 2023 12:22:20 +0000 Subject: [PATCH] [FIX] web: traceback when trying to add favorite filters without name Steps to reproduce: - Install Sales, Subscriptions or similar app. - Go to Sales, and try to save a favorite filter without name. - It can also be done in the order lines of the Subscriptions, if we try to add a product and select "search more", inside the new window try to add a favorite filter without name. Issue: We got a traceback that's not user friendly instead of the proper warning message, this is because inside the `saveFavorite` method we check if the description is empty, but we can't use `.length` because when we don't fill any name, the description is `undefined`. Solution: Removing the `.length` check, and just checking if the description is undefined or not. Forward bot up to master. opw-3200499 closes odoo/odoo#115204 X-original-commit: c0fe1408da48e43b3e7e55de8e1c1edb09c982d2 Signed-off-by: Mathieu Duckerts-Antoine --- .../js/control_panel/custom_favorite_item.js | 2 +- .../favorite_menu/custom_favorite_item.js | 2 +- .../search/custom_favorite_item_tests.js | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js b/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js index 6fbfe827b6c..27db3b680b9 100644 --- a/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js +++ b/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js @@ -53,7 +53,7 @@ odoo.define('web.CustomFavoriteItem', function (require) { * @private */ saveFavorite() { - if (!this.state.description.length) { + if (!this.state.description) { this.env.services.notification.notify({ message: this.env._t("A name for your favorite filter is required."), type: 'danger', diff --git a/addons/web/static/src/search/favorite_menu/custom_favorite_item.js b/addons/web/static/src/search/favorite_menu/custom_favorite_item.js index 3369b521bfb..f8c0441e29a 100644 --- a/addons/web/static/src/search/favorite_menu/custom_favorite_item.js +++ b/addons/web/static/src/search/favorite_menu/custom_favorite_item.js @@ -24,7 +24,7 @@ export class CustomFavoriteItem extends Component { * @param {Event} ev */ saveFavorite(ev) { - if (!this.state.description.length) { + if (!this.state.description) { this.notificationService.add( this.env._t("A name for your favorite filter is required."), { type: "danger" } diff --git a/addons/web/static/tests/search/custom_favorite_item_tests.js b/addons/web/static/tests/search/custom_favorite_item_tests.js index 1fbe3c9ef7e..090318b319e 100644 --- a/addons/web/static/tests/search/custom_favorite_item_tests.js +++ b/addons/web/static/tests/search/custom_favorite_item_tests.js @@ -345,6 +345,45 @@ QUnit.module("Search", (hooks) => { } ); + QUnit.test("undefined name for filter shows notification and not error", async function (assert) { + assert.expect(2); + + serviceRegistry.add( + "notification", + { + start() { + return { + add(message, options) { + assert.strictEqual( + message, + "A name for your favorite filter is required.", + "The notification should match: A name for your favorite filter is required." + ); + assert.deepEqual(options, { type: "danger" }); + }, + }; + }, + }, + { force: true } + ); + + await makeWithSearch({ + serverData, + mockRPC: (_, args) => { + if (args.model === "ir.filters" && args.method === "create_or_replace") { + return 7; // fake serverSideId + } + }, + resModel: "foo", + Component: FavoriteMenu, + searchViewId: false, + }); + + await toggleFavoriteMenu(target); + await toggleSaveFavorite(target); + await saveFavorite(target); + }); + QUnit.skip("save search filter in modal", async function (assert) { /** @todo I don't know yet how to convert this test */ // assert.expect(5);