【发布时间】:2020-05-22 10:49:49
【问题描述】:
任何人都可以按照这些步骤检查他们是否有同样的经历吗?
在 Odoo 版本 12 中(我还没有检查是否在其他版本中发生这种情况),修改任何产品,例如在 barcode 字段中写入 9700000175781 并保存。
打印带有条形码的产品报告标签。
使用条形码阅读器或任何条形码阅读器模拟器读取打印的标签。
好吧,我已经尝试过使用真正的条形码阅读器和几个模拟器。我要求我的同事在他们家中尝试同样的方法。
我们都得到 9700000175784。条形码 9700000175782、9700000175783...
也是如此但是,其他条形码可以正常工作。例如,9700000175784 被正确打印和阅读。
这是调用控制器的 Qweb 行:
<img alt="Barcode" t-if="len(product.barcode) == 13" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&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&value=%s&width=%s&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