0

随着odoo15的新变化。我无法覆盖 Javascript 中的函数。我创建了一个自定义模块并导入了所需的。

我想覆盖 _executeReportAction 函数

 import {download} from "@web/core/network/download";
 import {registry} from "@web/core/registry";
 import { useService } from "@web/core/utils/hooks";
 import {actionService} from "@web/webclient/actions/action_service";


 async function _executeReportAction(action, options) {

  }

那么怎么做

4

1 回答 1

0

_executeReportAction函数将首先尝试执行ir.actions.report 处理程序,因此不要修补该函数,而是添加一个zpl报告处理程序。

您可以检查 OCA report_xlsx模块,该模块定义了报告的报告处理xlsx程序

原始代码:

/** @odoo-module **/

import {download} from "@web/core/network/download";
import {registry} from "@web/core/registry";

registry
    .category("ir.actions.report handlers")
    .add("xlsx_handler", async function (action, options, env) {
        if (action.report_type === "xlsx") {
            const type = action.report_type;
            let url = `/report/${type}/${action.report_name}`;
            const actionContext = action.context || {};
            if (action.data && JSON.stringify(action.data) !== "{}") {
                // Build a query string with `action.data` (it's the place where reports
                // using a wizard to customize the output traditionally put their options)
                const action_options = encodeURIComponent(JSON.stringify(action.data));
                const context = encodeURIComponent(JSON.stringify(actionContext));
                url += `?options=${action_options}&context=${context}`;
            } else {
                if (actionContext.active_ids) {
                    url += `/${actionContext.active_ids.join(",")}`;
                }
                if (type === "xlsx") {
                    const context = encodeURIComponent(
                        JSON.stringify(env.services.user.context)
                    );
                    url += `?context=${context}`;
                }
            }
            env.services.ui.block();
            try {
                await download({
                    url: "/report/download",
                    data: {
                        data: JSON.stringify([url, action.report_type]),
                        context: JSON.stringify(env.services.user.context),
                    },
                });
            } finally {
                env.services.ui.unblock();
            }
            const onClose = options.onClose;
            if (action.close_on_report_download) {
                return env.services.action.doAction(
                    {type: "ir.actions.act_window_close"},
                    {onClose}
                );
            } else if (onClose) {
                onClose();
            }
            return Promise.resolve(true);
        }
        return Promise.resolve(false);
    });

在上面的代码中,他们将_triggerDownload_getReportUrl函数合并为一个函数。

于 2022-02-26T20:59:57.200 回答