我正在尝试将 QR 图像添加到 POS 收据中。我在正常发票中使用的有效代码如下:
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s'%('QR', o.qr_code_string, 150, 150)"/>
对于收据,我将字符串导出为receipt.qr_string,并将以下行添加到收据的继承 XML 文件中:
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s'%('QR', receipt.qr_string, 150, 150)"/>
但图像看起来像是一个断开的链接。我该如何实现这一目标?
我不知道为什么它不适用于 POS 收据,但让我告诉你,POS 是无需连接服务器即可运行的系统。它执行的所有内容都应该始终使用 js,我的意思是始终在客户端。所以,我的解决方案是使用 QRrcode.js 库,因为它很容易获得here.
将此库文件添加到路径上的模块中/<your_module/static/src/lib/
文件夹以及您的 pos 后端,如下所示,并且该文件需要添加到清单中以及“数据”文件列表下。
<odoo>
<data>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/<module_name>/static/src/lib/qrcode.js"></script>
</xpath>
</template>
</data>
</odoo>
妥善保管路径。
然后您可以在任何 POS Receipt Qweb 中使用该库,如下所示打印 QRcode。
<div t-attf-id="#{receipt.qr_string}"></div>
<script type="text/javascript">
var lot_name = "<t t-esc="receipt.qr_string"/>";
var qrcode = new QRCode(receipt.qr_string , {
text: "http://jindo.dev.naver.com/collie",
width: 100,
height: 100,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
qrcode.makeCode(receipt.qr_string);
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)