From aebb85fd51d0ff5b5c4855629a8dbb0ad97bffed Mon Sep 17 00:00:00 2001 From: miguels73 <55379877+miguels73@users.noreply.github.com> Date: Mon, 16 Jan 2023 09:28:50 +0100 Subject: [PATCH] [MIG] web_ir_actions_act_window_message: Migration to 16.0 --- .../__manifest__.py | 2 +- .../readme/CONTRIBUTORS.rst | 1 + .../web_ir_actions_act_window_message.esm.js | 30 +++++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/web_ir_actions_act_window_message/__manifest__.py b/web_ir_actions_act_window_message/__manifest__.py index ac31d88c5..321d03032 100644 --- a/web_ir_actions_act_window_message/__manifest__.py +++ b/web_ir_actions_act_window_message/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Client side message boxes", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "Therp BV, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", "license": "AGPL-3", diff --git a/web_ir_actions_act_window_message/readme/CONTRIBUTORS.rst b/web_ir_actions_act_window_message/readme/CONTRIBUTORS.rst index 5b061c7c1..b04bff5b4 100644 --- a/web_ir_actions_act_window_message/readme/CONTRIBUTORS.rst +++ b/web_ir_actions_act_window_message/readme/CONTRIBUTORS.rst @@ -3,6 +3,7 @@ * Benjamin Willig (ACSONE SA/NV) * Ioan Galan (Studio73) * Abraham Anes (Studio73) +* Miguel Gandia (Studio73) * `DynApps NV `_: * Koen Loodts diff --git a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.esm.js b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.esm.js index 8ef51075e..3e7e758af 100644 --- a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.esm.js +++ b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.esm.js @@ -1,7 +1,25 @@ /** @odoo-module **/ -import {registry} from "@web/core/registry"; import Dialog from "web.Dialog"; +import {registry} from "@web/core/registry"; + +function _refreshWidget(env) { + const controller = env.services.action.currentController; + const props = controller.props; + const view = controller.view; + // LEGACY CODE COMPATIBILITY: remove when controllers will be written in owl + if (view.isLegacy) { + // Case where a legacy view is reloaded via the view switcher + const {__legacy_widget__} = controller.getLocalState(); + const params = {}; + if ("resId" in props) { + params.currentId = props.resId; + } + return __legacy_widget__.reload(params); + } + // END LEGACY CODE COMPATIBILITY + env.services.action.switchView(props.type, {resId: props.resId}); +} function ir_actions_act_window_message_get_buttons(env, action, close_func) { // Return an array of button definitions from action @@ -22,11 +40,7 @@ function ir_actions_act_window_message_get_buttons(env, action, close_func) { if (_.isObject(result)) { return env.services.action.doAction(result); } - // Always refresh the view after the action - // ex: action updates a status - const {__legacy_widget__} = - env.services.action.currentController.getLocalState(); - __legacy_widget__.reload({}); + _refreshWidget(env); }); } else { return env.services.action.doAction(button_definition); @@ -44,9 +58,7 @@ async function _executeWindowMessageAction({env, action}) { text: action.close_button_title || env._t("Close"), click: function () { // Refresh the view before closing the dialog - const {__legacy_widget__} = - env.services.action.currentController.getLocalState(); - __legacy_widget__.reload({}); + _refreshWidget(env); this.close(); }, classes: "btn-default",