odoo15 前端学习

1: report action 得管理,  D:\opt\odoo15\addons\web\static\src\webclient\actions\action_service.js   line:1015

    async function _executeReportAction(action, options) {
const handlers
= registry.category("ir.actions.report handlers").getAll(); //注册一个报表处理把手集合, 后续代码出要扩展,就通过该这个对应的注册器 add 添加
     //循环处理所有句柄, 可知句柄可以传入三个参数 action, options, env
for (const handler of handlers) { const result = await handler(action, options, env); if (result) { return result; } }
if (action.report_type === "qweb-html") { return _executeReportClientAction(action, options); } else if (action.report_type === "qweb-pdf") { // check the state of wkhtmltopdf before proceeding if (!wkhtmltopdfStateProm) { wkhtmltopdfStateProm = env.services.rpc("/report/check_wkhtmltopdf"); }

#根据上访思路,加入要扩展 py3o 报表

/** @odoo-module **/

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

console.info('===============');

registry
    .category("ir.actions.report handlers")
    .add("py3o", async function (action, options, env) {  // 通过注册器,添加对应的句柄,参数是3个
        if (action.report_type === "py3o") { //注意,句柄是循环遍历的,所以必须要判断对应的类型,
    
        //这里开始,其实就是为了抄袭返回 _triggerDownload 方法, js不知道如何像python一样直接import这个方法,所以只好抄过来重新实现一遍, let type
= 'py3o' 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 options = encodeURIComponent(JSON.stringify(action.data)); const context = encodeURIComponent(JSON.stringify(actionContext)); url += `?options=${options}&context=${context}`; } else { if (actionContext.active_ids) { url += `/${actionContext.active_ids.join(",")}`; } } 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(); } } return Promise.resolve(false); });

 

posted on 2022-11-18 23:49  Odoo在中国  阅读(134)  评论(0编辑  收藏  举报

导航