【问题标题】:Why my printed barcodes are wrong in Odoo 12?为什么我打印的条形码在 Odoo 12 中是错误的?
【发布时间】:2020-05-22 10:49:49
【问题描述】:

任何人都可以按照这些步骤检查他们是否有同样的经历吗?

在 Odoo 版本 12 中(我还没有检查是否在其他版本中发生这种情况),修改任何产品,例如在 barcode 字段中写入 9700000175781 并保存。

打印带有条形码的产品报告标签。

使用条形码阅读器或任何条形码阅读器模拟器读取打印的标签。

好吧,我已经尝试过使用真正的条形码阅读器和几个模拟器。我要求我的同事在他们家中尝试同样的方法。

我们都得到 9700000175784。条形码 97000001757829700000175783...

也是如此

但是,其他条形码可以正常工作。例如,9700000175784 被正确打印和阅读。

这是调用控制器的 Qweb 行:

<img alt="Barcode" t-if="len(product.barcode) == 13" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height:4rem;"/>

控制器调用ir.actions.report模型的方法barcode

@http.route(['/report/barcode', '/report/barcode/<type>/<path:value>'], type='http', auth="public")
def report_barcode(self, type, value, width=600, height=100, humanreadable=0):
    """Contoller able to render barcode images thanks to reportlab.
    Samples:
        <img t-att-src="'/report/barcode/QR/%s' % o.name"/>
        <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' %
            ('QR', o.name, 200, 200)"/>

    :param type: Accepted types: 'Codabar', 'Code11', 'Code128', 'EAN13', 'EAN8', 'Extended39',
    'Extended93', 'FIM', 'I2of5', 'MSI', 'POSTNET', 'QR', 'Standard39', 'Standard93',
    'UPCA', 'USPS_4State'
    :param humanreadable: Accepted values: 0 (default) or 1. 1 will insert the readable value
    at the bottom of the output image
    """
    try:
        barcode = request.env['ir.actions.report'].barcode(type, value, width=width, height=height, humanreadable=humanreadable)
    except (ValueError, AttributeError):
        raise werkzeug.exceptions.HTTPException(description='Cannot convert into barcode.')

    return request.make_response(barcode, headers=[('Content-Type', 'image/png')])

barcode 方法使用reportlab 库来绘制条形码:

from reportlab.graphics.barcode import createBarcodeDrawing
...

@api.model
def barcode(self, barcode_type='EAN13', value=quote_plus(product.barcode or ''), width=600, height=150, humanreadable=0):
    if barcode_type == 'UPCA' and len(value) in (11, 12, 13):
        barcode_type = 'EAN13'
        if len(value) in (11, 12):
            value = '0%s' % value
    try:
        width, height, humanreadable = int(width), int(height), bool(int(humanreadable))
        barcode = createBarcodeDrawing(
            barcode_type, value=value, format='png', width=width, height=height,
            humanReadable=humanreadable
        )
        return barcode.asString('png')
    except (ValueError, AttributeError):
        if barcode_type == 'Code128':
            raise ValueError("Cannot convert into barcode.")
        else:
            return self.barcode('Code128', value, width=width, height=height, humanreadable=humanreadable)

我的结论

由于参数到达使用 reportlab 的行是正常的,我认为问题出在库 reportlab 上。有没有人有同样的经历并知道会发生什么?这还没有向 Odoo 或 reportlab 报告,这真的很奇怪。版本有问题吗?

我已经尝试过 3.4.0 和最新的 3.5.42。

【问题讨论】:

    标签: python-3.x odoo reportlab odoo-12 qweb


    【解决方案1】:

    解决了。没有编程问题...

    EAN13 9700000175781 是错误的。第 13 个数字,称为控制数字,必须根据其余数字完成一些操作。在这种情况下,前十二位数字 970000017578 生成控制数字 4,而不是 1

    reportlab 只是忽略您发送的用于绘制的控制数字并打印正确的数字,所以在这种情况下,其他的(97000001757829700000175783 strong> 等),控制位由 4 代替。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      • 2014-11-23
      • 1970-01-01
      • 2021-09-26
      • 2019-08-02
      相关资源
      最近更新 更多