[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 <dam@odoo.com>
This commit is contained in:
Maruan Aguerdouh (magm)
2023-03-21 09:36:07 +01:00
parent 055af0b0af
commit cb345ea1e7
3 changed files with 41 additions and 2 deletions
@@ -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',
@@ -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" }
@@ -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);