如何在 Odoo POS 收据中添加二维码图像

Posted

技术标签:

【中文标题】如何在 Odoo POS 收据中添加二维码图像【英文标题】:How to add QR code image in Odoo's POS receipt 【发布时间】:2020-08-06 04:42:34 【问题描述】:

我正在尝试将 QR 图像添加到 POS 的收据中。我在正常发票中使用的代码如下:

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s'%('QR', o.qr_code_string, 150, 150)"/>

对于收据,我将我的字符串导出为receipt.qr_string,并将以下行添加到收据的继承XML文件中:

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s'%('QR', receipt.qr_string, 150, 150)"/>

但图像看起来像一个断开的链接。我如何做到这一点?

【问题讨论】:

【参考方案1】:

我不知道为什么它不适用于 POS 收据,但让我告诉你,POS 是无需连接到服务器即可运行的系统。它执行的一切都应该始终使用 js,我的意思是始终使用客户端。所以,我的解决方案是使用 QRrcode.js 库,因为它很容易获得here.

将此库文件添加到路径 /&lt;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 中使用该库来打印二维码。

<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>

【讨论】:

谢谢@Chavada Viki,它工作得很好。我对这个解决方案还有一个疑问,如何更改 QR 的对齐方式?即使我使用 content-align 或 text-align,它也会留在收据的左侧。 @SimonCapriles 这完全是一个 CSS 模组。我不知道收据和其他模组的当前设计是什么。但是是的,您只能在屏幕上打印的 POS 收据上使用此类和 css。对于从 POS Receipt printe 出来的收据,不能使用 css 或类。我的意思是两个模板是不同的。

以上是关于如何在 Odoo POS 收据中添加二维码图像的主要内容,如果未能解决你的问题,请参考以下文章