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

如何在Odoo报表生成的二维码中嵌入自定义跳转URL链接

解决方案

方式1:沿用现有%格式化语法

直接在value参数位置完成域名和doc.id的拼接,修改后的完整代码如下:

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', 'https://example.com/%s' % doc.id, 600, 50)" style="width:30px;height:30px;"/>

方式2:用+号直接拼接字符串

也可以用Python基础的字符串相加写法,逻辑更直观:

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', 'https://example.com/' + str(doc.id), 600, 50)" style="width:30px;height:30px;"/>

优化建议

如果需要适配多部署环境,避免硬编码域名,可以调用Odoo系统内置的基础域名参数web.base.url,写法如下:

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', request.env['ir.config_parameter'].sudo().get_param('web.base.url') + '/%s' % doc.id, 600, 50)" style="width:30px;height:30px;"/>

内容的提问来源于stack exchange,提问作者Pol López

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.14 12:57:02