From 6d9302c78670f33a793defb823976a6084a26558 Mon Sep 17 00:00:00 2001 From: dise-odoo Date: Mon, 6 Nov 2023 12:21:21 +0100 Subject: [PATCH] [FIX] project_todo: missing "add a to-do" in the command palette Task 3300854 would remove the "add a to-do" action in the systray, but by doing so, it removed the action in the command palette as well. This PR will re-add the action in the command palette. The ActivityMenu component is patched to add the command each time it is loaded. task-3580533 closes odoo/odoo#141168 Signed-off-by: Xavier Bol (xbo) --- addons/project_todo/__manifest__.py | 1 + addons/project_todo/i18n/project_todo.pot | 8 ++++ .../src/web/activity/activity_menu_patch.js | 45 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 addons/project_todo/static/src/web/activity/activity_menu_patch.js diff --git a/addons/project_todo/__manifest__.py b/addons/project_todo/__manifest__.py index e0ea34570d0..1fe9af07c14 100644 --- a/addons/project_todo/__manifest__.py +++ b/addons/project_todo/__manifest__.py @@ -28,6 +28,7 @@ 'project_todo/static/src/components/**/*', 'project_todo/static/src/scss/todo.scss', 'project_todo/static/src/views/**/*', + 'project_todo/static/src/web/**/*', ], }, 'license': 'LGPL-3', diff --git a/addons/project_todo/i18n/project_todo.pot b/addons/project_todo/i18n/project_todo.pot index 900612c1ad8..2efe8219b8d 100644 --- a/addons/project_todo/i18n/project_todo.pot +++ b/addons/project_todo/i18n/project_todo.pot @@ -186,6 +186,14 @@ msgstr "" msgid "Add To-Do" msgstr "" +#. module: project_todo +#. odoo-javascript +#: code:addons/project_todo/static/src/web/activity/activity_menu_patch.js:0 +#: code:addons/project_todo/static/src/web/activity/activity_menu_patch.js:0 +#, python-format +msgid "Add a To-Do" +msgstr "" + #. module: project_todo #: model_terms:ir.ui.view,arch_db:project_todo.mail_activity_todo_create_popup msgid "Add details about your to-do..." diff --git a/addons/project_todo/static/src/web/activity/activity_menu_patch.js b/addons/project_todo/static/src/web/activity/activity_menu_patch.js new file mode 100644 index 00000000000..d5ddbea81b2 --- /dev/null +++ b/addons/project_todo/static/src/web/activity/activity_menu_patch.js @@ -0,0 +1,45 @@ +/** @odoo-module **/ + +import { _t } from "@web/core/l10n/translation"; +import { ActivityMenu } from "@mail/core/web/activity_menu"; +import { FormViewDialog } from "@web/views/view_dialogs/form_view_dialog"; +import { useCommand } from "@web/core/commands/command_hook"; +import { useService } from "@web/core/utils/hooks"; +import { patch } from "@web/core/utils/patch"; +import { registry } from "@web/core/registry"; + +// Add a to-do category for the command palette +registry.category("command_categories").add("to-do", {}, { sequence: 105 }); + +patch(ActivityMenu.prototype, { + setup() { + super.setup(...arguments); + this.orm = useService("orm"); + this.dialogService = useService("dialog"); + useCommand( + _t("Add a To-Do"), + () => { + document.body.click(); // hack to close command palette + this.createActivityTodo(); + }, + { + category: "to-do", + hotkey: "alt+control+l", + global: true, + } + ); + }, + + async createActivityTodo() { + const wizard = await this.orm.call("mail.activity.todo.create", "create", [{ + "user_id": this.userId, + }]); + this.dialogService.add(FormViewDialog, { + title: _t("Add a To-Do"), + resModel: "mail.activity.todo.create", + resId: wizard, + preventCreate: true, + size: "md", + }); + }, +});