Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

中文生产单打印,日期项不能打印



  • 生产单打印:两个日期项不能打印,请看附图

    语言改成英文就没有问题

    Server:Ubuntu 10.04 LTS, OpenERP 5.0.15  ;
    GTK Client 5.0.15, Web Client 都有问题

    Chip




  • 报表模板问题吧? 模板修改过?
    打印日期 的 formatLang 怎么变成 matLang 了...



  • [quote]
    [2011-03-16 11:51:12,280][cylindro] ERROR:report:[01]:
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[02]: Environment Information :
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[03]: System : Linux-2.6.32-29-generic-i686-with-Ubuntu-10.04-lucid
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[04]: OS Name : posix
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[05]: Distributor ID:  Ubuntu
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[06]: Description:  Ubuntu 10.04.2 LTS
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[07]: Release:  10.04
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[08]: Codename:  lucid
    [2011-03-16 11:51:12,281][cylindro] ERROR:report:[09]: Operating System Release : 2.6.32-29-generic
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[10]: Operating System Version : #58-Ubuntu SMP Fri Feb 11 19:00:09 UTC 2011
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[11]: Operating System Architecture : 32bit
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[12]: Operating System Locale : NOT SET
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[13]: Python Version : 2.6.5
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[14]: OpenERP-Server Version : 5.0.15
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[15]: Last revision No. & ID :
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[16]: report :
    [2011-03-16 11:51:12,282][cylindro] ERROR:report:[17]: Traceback (most recent call last):
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[18]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/render/rml2pdf/utils.py", line 116, in _process_text
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[19]:    txt = eval(expr,self.localcontext)
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[20]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/tools/safe_eval.py", line 274, in safe_eval
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[21]:    return eval(test_expr(expr,_SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[22]:  File "", line 1, in <module>
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[23]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/report_sxw.py", line 251, in formatLang
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[24]:    if not str(value):
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[25]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/report_sxw.py", line 126, in str
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[26]:    return datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format)
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[27]: UnicodeEncodeError: 'ascii' codec can't encode character u'\u5e74' in position 2: ordinal not in range(128)
    [2011-03-16 11:51:12,284][cylindro] ERROR:report:[28]:
    [2011-03-16 11:51:12,284][cylindro] ERROR:report:[29]: 'ascii' codec can't encode character u'\u5e74' in position 2: ordinal not in range(128)
    [2011-03-16 11:51:12,284][cylindro] ERROR:report:[30]: expr: formatLang(o.date_planned, date_time = True)
    [/quote]

    不是报表模板的问题,报表模板没有动过
    新安装,什么也不做,就会这样



  • self.lang_obj.date_format+ " " + self.lang_obj.time_format

    把这个串 先输出一下..然后 转换为 Unicode 串...



  • 我这样弄的:

    &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; dt_text = unicode( self.lang_obj.date_format+ &quot; &quot; + self.lang_obj.time_format, &#039;utf-8&#039; )<br />&nbsp; &nbsp; &nbsp; &nbsp; return datetime.strftime(dt_text)<br />
    


    不行,结果是这样:

    [quote]
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[16]: report :
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[17]: Traceback (most recent call last):
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[18]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/render/rml2pdf/utils.py", line 116, in _process_text
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[19]:    txt = eval(expr,self.localcontext)
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[20]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/tools/safe_eval.py", line 274, in safe_eval
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[21]:    return eval(test_expr(expr,_SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[22]:  File "", line 1, in <module>
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[23]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/report_sxw.py", line 254, in formatLang
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[24]:    if not str(value):
    [2011-03-16 15:47:33,762][cylindro] ERROR:report:[25]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/report_sxw.py", line 126, in str
    [2011-03-16 15:47:33,763][cylindro] ERROR:report:[26]:    dt_text = unicode( self.lang_obj.date_format+ " " + self.lang_obj.time_format, 'utf-8' )
    [2011-03-16 15:47:33,763][cylindro] ERROR:report:[27]: TypeError: decoding Unicode is not supported
    [2011-03-16 15:47:33,763][cylindro] ERROR:report:[28]:
    [2011-03-16 15:47:33,763][cylindro] ERROR:report:[29]: decoding Unicode is not supported
    [2011-03-16 15:47:33,763][cylindro] ERROR:report:[30]: expr: formatLang(o.date_planned, date_time = True)
    [/quote]

    恕弟愚钝,还望详示
    我Python的,Noob


  • 管理员

    [quote[2011-03-16 11:51:12,283][cylindro] ERROR:report:[23]:  File  "/usr/local/lib/python2.6/dist-packages/openerp-server/report/report_sxw.py",  line 251, in formatLang
    [2011-03-16 11:51:12,283][cylindro] ERROR:report:[24]:    if not str(value):]
    从以上你贴出的log中可以看到在report_sxw.py模块的第251行用了str(value), 而这个value中应该有无法用ASCII编码的unicode字串(中文日期格式),str()默认使用ASCII来编码该字串从而导致错误。你可以试试用:

    from tools import ustr<br />ustr(value)
    


    来替代这行代码,试试。
    我的没有装5.x的版本,你可以试试,看看结果如何



  • Hi digitalsatori,

    结果是这样:

    [quote]
    [2011-03-16 21:43:17,646][cylindro] ERROR:report:[16]: report :
    [2011-03-16 21:43:17,646][cylindro] ERROR:report:[17]: Traceback (most recent call last):
    [2011-03-16 21:43:17,646][cylindro] ERROR:report:[18]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/render/rml2pdf/utils.py", line 116, in _process_text
    [2011-03-16 21:43:17,646][cylindro] ERROR:report:[19]:    txt = eval(expr,self.localcontext)
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[20]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/tools/safe_eval.py", line 274, in safe_eval
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[21]:    return eval(test_expr(expr,_SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[22]:  File "", line 1, in <module>
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[23]:  File "/usr/local/lib/python2.6/dist-packages/openerp-server/report/report_sxw.py", line 277, in formatLang
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[24]:    return date.strftime(date_format)
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[25]: UnicodeEncodeError: 'ascii' codec can't encode character u'\u5e74' in position 2: ordinal not in range(128)
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[26]:
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[27]: 'ascii' codec can't encode character u'\u5e74' in position 2: ordinal not in range(128)
    [2011-03-16 21:43:17,647][cylindro] ERROR:report:[28]: expr: formatLang(o.date_planned, date_time = True)
    [/quote]

    strftime 不支持unicode 参数


  • 管理员

    不好意思value本来就是unicode string了,应该encode成byte string
    硬编码试试

    value.encode(&#039;utf8&#039;)
    



  • 先按校长说的,把str 改成 ustr,

    再按mrshelly说的,这样改:

    <br />&nbsp; &nbsp; return date.strftime(date_format.encode(&#039;utf-8&#039;)).decode(&#039;utf-8&#039;)<br />
    


    就行了

    出问题的原因是因为str和Python的strftime不支持Unicode.

    再次感谢两位的指导!

    Chip