[IMP] web_refresher: Provide the ability to reload information from a report view

This commit is contained in:
Carlos Roca
2024-02-07 14:33:53 +01:00
parent 4c7b800293
commit 9941a58328
5 changed files with 46 additions and 4 deletions

View File

@@ -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);
}
},
});

View File

@@ -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});
}
}