如何在Odoo报表生成的二维码中嵌入自定义跳转URL链接
解决方案
方式1:沿用现有%格式化语法
直接在value参数位置完成域名和doc.id的拼接,修改后的完整代码如下:
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&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&value=%s&width=%s&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&value=%s&width=%s&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
相关产品推荐
相关产品推荐

