From 9941a58328ceaf55b600ec9ca72243155e577d31 Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Wed, 7 Feb 2024 14:33:53 +0100 Subject: [PATCH] [IMP] web_refresher: Provide the ability to reload information from a report view --- web_refresher/README.rst | 2 +- web_refresher/__manifest__.py | 1 + web_refresher/static/description/index.html | 2 +- .../src/js/client_action_adapter.esm.js | 28 +++++++++++++++++++ web_refresher/static/src/js/refresher.esm.js | 17 +++++++++-- 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 web_refresher/static/src/js/client_action_adapter.esm.js diff --git a/web_refresher/README.rst b/web_refresher/README.rst index f727b0a87fe3..0dff42728835 100644 --- a/web_refresher/README.rst +++ b/web_refresher/README.rst @@ -7,7 +7,7 @@ Web Refresher !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:88fce35323996a71b86623ff97b9a099bd381b6c37a3cb2ca6ba41179c04926d + !! source digest: sha256:f8d8ed8f9762830a5153097507a407ee9523c05093d1b424ae19dc30ccef9486 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/web_refresher/__manifest__.py b/web_refresher/__manifest__.py index 59186f2a430f..4956d69dd01a 100644 --- a/web_refresher/__manifest__.py +++ b/web_refresher/__manifest__.py @@ -10,6 +10,7 @@ "assets": { "web.assets_backend": [ "web_refresher/static/src/scss/refresher.scss", + "web_refresher/static/src/js/client_action_adapter.esm.js", "web_refresher/static/src/js/refresher.esm.js", "web_refresher/static/src/js/control_panel.esm.js", ], diff --git a/web_refresher/static/description/index.html b/web_refresher/static/description/index.html index 6a5a5f3548a2..192f388979aa 100644 --- a/web_refresher/static/description/index.html +++ b/web_refresher/static/description/index.html @@ -367,7 +367,7 @@

Web Refresher

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:88fce35323996a71b86623ff97b9a099bd381b6c37a3cb2ca6ba41179c04926d +!! source digest: sha256:f8d8ed8f9762830a5153097507a407ee9523c05093d1b424ae19dc30ccef9486 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

Adds a button next to the pager (in trees/kanban views) to refresh the displayed list.

diff --git a/web_refresher/static/src/js/client_action_adapter.esm.js b/web_refresher/static/src/js/client_action_adapter.esm.js new file mode 100644 index 000000000000..00dd7689a414 --- /dev/null +++ b/web_refresher/static/src/js/client_action_adapter.esm.js @@ -0,0 +1,28 @@ +/** @odoo-module **/ +/* Copyright 2024 Tecnativa - Carlos Roca + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ +import {ClientActionAdapter} from "@web/legacy/action_adapters"; +import Context from "web.Context"; +import {mapDoActionOptionAPI} from "@web/legacy/backend_utils"; +import {patch} from "@web/core/utils/patch"; +import {wrapSuccessOrFail} from "@web/legacy/utils"; + +patch(ClientActionAdapter.prototype, "web_refresher.ClientActionAdapter", { + _trigger_up(ev) { + const payload = ev.data; + if (ev.name === "refresh_report") { + this.actionService.restore(payload.controllerID).then(() => { + if (payload.action.context) { + payload.action.context = new Context(payload.action.context).eval(); + } + const legacyOptions = mapDoActionOptionAPI(payload.options); + wrapSuccessOrFail( + this.actionService.doAction(payload.action, legacyOptions), + payload + ); + }); + } else { + this._super(...arguments); + } + }, +}); diff --git a/web_refresher/static/src/js/refresher.esm.js b/web_refresher/static/src/js/refresher.esm.js index 0d643d99e920..858ef452fd55 100644 --- a/web_refresher/static/src/js/refresher.esm.js +++ b/web_refresher/static/src/js/refresher.esm.js @@ -1,15 +1,28 @@ /** @odoo-module **/ /* Copyright 2022 Tecnativa - Alexandre D. Díaz - * Copyright 2022 Tecnativa - Carlos Roca + * Copyright 2022-2024 Tecnativa - Carlos Roca * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ const {Component} = owl; export class Refresher extends Component { _doRefresh() { + // Allow refresh reports + if (["ir.actions.report", "ir.actions.client"].includes(this.env.action.type)) { + const options = {}; + const breadcrumbs = this.__owl__.parent.props.breadcrumbs; + if (breadcrumbs.length) { + return this.trigger("refresh-report", { + action: this.env.action, + controllerID: breadcrumbs.slice(-1).controllerID, + }); + } + options.clear_breadcrumbs = true; + return this.trigger("do-action", {action: this.env.action, options}); + } // Note: here we use the pager props, see xml const {limit, currentMinimum} = this.props; - this.trigger("pager-changed", {currentMinimum, limit}); + return this.trigger("pager-changed", {currentMinimum, limit}); } }