From b842cf4e397baf89e891ea0049f4321fea73f005 Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Tue, 9 Apr 2024 10:22:49 +0200 Subject: [PATCH] [IMP] web_refresher: Be able to refresh from report views --- web_refresher/static/src/js/refresher.esm.js | 32 ++++++++++++++------ web_refresher/static/src/xml/refresher.xml | 7 +---- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/web_refresher/static/src/js/refresher.esm.js b/web_refresher/static/src/js/refresher.esm.js index 60c570ad9..d7b72f014 100644 --- a/web_refresher/static/src/js/refresher.esm.js +++ b/web_refresher/static/src/js/refresher.esm.js @@ -6,6 +6,7 @@ import {Component} from "@odoo/owl"; import {useDebounced} from "@web/core/utils/timing"; +import {useService} from "@web/core/utils/hooks"; export function useRefreshAnimation(timeout) { const refreshClass = "o_content__refresh"; @@ -41,19 +42,11 @@ export function useRefreshAnimation(timeout) { export class Refresher extends Component { setup() { super.setup(); + this.action = useService("action"); this.refreshAnimation = useRefreshAnimation(1000); this.onClickRefresh = useDebounced(this.onClickRefresh, 200); } - /** - * @returns {Boolean} - */ - get displayButton() { - const {searchModel, pagerProps} = this.props; - const hasSearchModel = searchModel && searchModel.search; - return Boolean(hasSearchModel || (pagerProps && pagerProps.onUpdate)); - } - /** * @returns {Boolean} * @private @@ -92,7 +85,28 @@ export class Refresher extends Component { return updated; } + /** + * Function to refresh the views that has not the props + * required by the refresher, like ir.actions.report or + * ir.actions.client. + */ + async refreshReport() { + const viewAction = this.action.currentController.action; + const options = {}; + if (this.env.config.breadcrumbs.length > 1) { + const breadcrumb = this.env.config.breadcrumbs.slice(-1); + await this.action.restore(breadcrumb.jsId); + } else { + options.clearBreadcrumbs = true; + } + this.action.doAction(viewAction, options); + } + async onClickRefresh() { + const {searchModel, pagerProps} = this.props; + if (!searchModel && !pagerProps) { + return this.refreshReport(); + } const updated = await this.refresh(); if (updated) { this.refreshAnimation(); diff --git a/web_refresher/static/src/xml/refresher.xml b/web_refresher/static/src/xml/refresher.xml index 59954a478..4827c5a65 100644 --- a/web_refresher/static/src/xml/refresher.xml +++ b/web_refresher/static/src/xml/refresher.xml @@ -4,12 +4,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->