You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现Qweb Report对Odoo外部用户的公开访问?

Odoo报表允许外部用户访问的实现方法

方法1:生成带访问令牌的公开链接

Odoo原生支持通过记录的access_token生成无需登录的报表链接,每个记录的令牌唯一且安全:

  • 访问格式示例:http://192.168.0.158:8020/report/pdf/account.report_invoice/20?access_token=XXX
  • 获取令牌方式:
    1. 开启开发模式,打开目标发票(account.move记录),查看access_token字段的值
    2. 或通过Python代码生成:
      invoice = env['account.move'].browse(20)
      public_url = f"{invoice.get_base_url()}/report/pdf/account.report_invoice/{invoice.id}?access_token={invoice.access_token}"
      
  • 优势:仅持有令牌的用户可访问对应报表,安全性可控。

方法2:调整报表权限(谨慎使用)

若需让某类报表全部公开,可修改报表的权限配置:

  • 开启开发模式,进入「设置-技术-报表」,找到account.report_invoice
  • 将报表的groups_id设置为空,或添加public用户组
  • 注意:此操作会让所有该类型报表对未登录用户开放,存在数据泄露风险,仅适用于无敏感数据的场景。

方法3:自定义公开控制器路由

通过开发自定义模块,创建跳过登录验证的报表访问路由:

from odoo import http
from odoo.http import request

class PublicInvoiceReport(http.Controller):
    @http.route('/public/report/invoice/pdf/<int:invoice_id>', auth='public')
    def public_invoice_report(self, invoice_id, **kwargs):
        invoice = request.env['account.move'].sudo().browse(invoice_id)
        if not invoice.exists():
            return request.not_found()
        # 生成并返回PDF报表
        pdf, _ = request.env['ir.actions.report']._render_qweb_pdf('account.report_invoice', [invoice_id])
        return request.make_response(pdf, headers=[
            ('Content-Type', 'application/pdf'),
            ('Content-Disposition', f'inline; filename="invoice_{invoice.name}.pdf"')
        ])
  • 部署模块后,外部用户可通过http://192.168.0.158:8020/public/report/invoice/pdf/20直接访问报表
  • 注意:需做好参数校验,避免非法访问其他记录,适合有开发能力的场景。

内容的提问来源于stack exchange,提问作者Satish Prajapati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 21:34:54