我正在尝试将二维码图像添加到 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 后端,如下所示,并且该文件需要添加到 list 中以及“数据”文件列表下。
<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>
关于odoo - 如何在 Odoo POS 收据中添加二维码图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61377362/