加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

打印产品标签时,不能显示条形码的错误排查

(2017-11-08 21:49:50)
分类: odoo10
遇到的问题:
  在产品信息中输入了条码数值后, 打印产品标签时, 条形码并未打印出来, 而是显示成了一个虚框

故障排查:
   (1) 在浏览器的地址栏中输入
http://地址:端口/report/barcode?type=EAN13&value=12345678&width=600&height=100
例如:
http://119.23.246.54:8069/report/barcode?type=EAN13&value=12345678&width=600&height=100
看网站上能否显示出条形码。

如果能显示出 ,那么错误的原因是生成的条形码没有能嵌入到报表中, 
涉及到的文件:addons\product\report\product_product_templates.xml
内容:
<template id="report_simple_label">
....
<img t-if="product.barcode"
   t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' 
      % ('EAN13', product.barcode, 600, 150)" style="width:100%;height:20%;"/>

(2) 如果在浏览器中不能显示出条码图片,可执行如下代码段, 检查reportlab库是否出现了问题
# -*- coding: utf-8 -*-
from reportlab.graphics.barcode import createBarcodeDrawing
barcode_type="EAN13"
value ="01234567892"
width=600
height=100
humanreadable=1
barcode = createBarcodeDrawing(
                barcode_type, value=value, format='png', width=width, height=height,
                humanReadable=humanreadable
            )
image= barcode.asString('png')
print  image
上述代码段 依据文件 odoo\addons\report\models\report.py

如下是一例出错信息
Traceback (most recent call last):
  File "barcode.py", line 18, in
    image= barcode.asString('png')
  File "D:\python27\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\graphics\shapes.py", line 833, in asString
    rl_config.showBoundary),**_extraKW(self,'_renderPM_',**kw))
  File "D:\python27\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\graphics\renderPM.py", line 665, in drawToString
    drawToFile(d,s,fmt=fmt, dpi=dpi, bg=bg, configPIL=configPIL)
  File "D:\python27\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\graphics\renderPM.py", line 661, in drawToFile
    c.saveToFile(fn,fmt)
  File "D:\python27\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\graphics\renderPM.py", line 291, in saveToFile
    im = self.toPIL()
  File "D:\python27\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\graphics\renderPM.py", line 287, in toPIL
    im.fromstring(self._gs.pixBuf)
  File "D:\python27\lib\site-packages\pillow-4.2.1-py2.7-win32.egg\PIL\Image.py", line 763, in fromstring
    self.load()
NotImplementedError: fromstring() has been removed. Please call frombytes() instead.

(3) 如果上述代码段能正常执行, 但是浏览上述网址不能显示出条码, 可能是odoo的服务出现了问题
这时,在odoo的服务器端日志中, 应该能显示出相关信息

涉及到的文件:addons\report\controllers\main.py
相关内容

    @route(['/report/barcode', '/report/barcode//'], type='http', auth="public")
    def report_barcode(self, type, value, width=600, height=100, humanreadable=0):
       ......
        try:
            barcode = request.env['report'].barcode(type, value, width=width, height=height, humanreadable=humanreadable)
        except (ValueError, AttributeError):
            raise exceptions.HTTPException(description='Cannot convert into barcode.')

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


  

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有