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

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

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

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

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



  • 生产单打印:两个日期项不能打印,请看附图<br /><br />语言改成英文就没有问题<br /><br />Server:Ubuntu 10.04 LTS, OpenERP 5.0.15  ; <br />GTK Client 5.0.15, Web Client 都有问题<br /><br />Chip <br /><br /><br />



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



  • [quote]<br />[2011-03-16 11:51:12,280][cylindro] ERROR:report:[01]:<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[02]: Environment Information :<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[03]: System : Linux-2.6.32-29-generic-i686-with-Ubuntu-10.04-lucid<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[04]: OS Name : posix<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[05]: Distributor ID:  Ubuntu<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[06]: Description:  Ubuntu 10.04.2 LTS<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[07]: Release:  10.04<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[08]: Codename:  lucid<br />[2011-03-16 11:51:12,281][cylindro] ERROR:report:[09]: Operating System Release : 2.6.32-29-generic<br />[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<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[11]: Operating System Architecture : 32bit<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[12]: Operating System Locale : NOT SET<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[13]: Python Version : 2.6.5<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[14]: OpenERP-Server Version : 5.0.15<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[15]: Last revision No. & ID :<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[16]: report :<br />[2011-03-16 11:51:12,282][cylindro] ERROR:report:[17]: Traceback (most recent call last):<br />[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<br />[2011-03-16 11:51:12,283][cylindro] ERROR:report:[19]:    txt = eval(expr,self.localcontext)<br />[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<br />[2011-03-16 11:51:12,283][cylindro] ERROR:report:[21]:    return eval(test_expr(expr,_SAFE_OPCODES, mode=mode), globals_dict, locals_dict)<br />[2011-03-16 11:51:12,283][cylindro] ERROR:report:[22]:  File "", line 1, in <module><br />[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<br />[2011-03-16 11:51:12,283][cylindro] ERROR:report:[24]:    if not str(value):<br />[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<br />[2011-03-16 11:51:12,283][cylindro] ERROR:report:[26]:    return datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format)<br />[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)<br />[2011-03-16 11:51:12,284][cylindro] ERROR:report:[28]:<br />[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)<br />[2011-03-16 11:51:12,284][cylindro] ERROR:report:[30]: expr: formatLang(o.date_planned, date_time = True)<br />[/quote]<br /><br />不是报表模板的问题,报表模板没有动过<br />新安装,什么也不做,就会这样<br />



  • self.lang_obj.date_format+ " " + self.lang_obj.time_format<br /><br />把这个串 先输出一下..然后 转换为 Unicode 串...



  • 我这样弄的:<br />

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

    <br />不行,结果是这样:<br /><br />[quote]<br />[2011-03-16 15:47:33,762][cylindro] ERROR:report:[16]: report :<br />[2011-03-16 15:47:33,762][cylindro] ERROR:report:[17]: Traceback (most recent call last):<br />[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<br />[2011-03-16 15:47:33,762][cylindro] ERROR:report:[19]:    txt = eval(expr,self.localcontext)<br />[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<br />[2011-03-16 15:47:33,762][cylindro] ERROR:report:[21]:    return eval(test_expr(expr,_SAFE_OPCODES, mode=mode), globals_dict, locals_dict)<br />[2011-03-16 15:47:33,762][cylindro] ERROR:report:[22]:  File "", line 1, in <module><br />[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<br />[2011-03-16 15:47:33,762][cylindro] ERROR:report:[24]:    if not str(value):<br />[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<br />[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' )<br />[2011-03-16 15:47:33,763][cylindro] ERROR:report:[27]: TypeError: decoding Unicode is not supported<br />[2011-03-16 15:47:33,763][cylindro] ERROR:report:[28]: <br />[2011-03-16 15:47:33,763][cylindro] ERROR:report:[29]: decoding Unicode is not supported<br />[2011-03-16 15:47:33,763][cylindro] ERROR:report:[30]: expr: formatLang(o.date_planned, date_time = True)<br />[/quote]<br /><br />恕弟愚钝,还望详示<br />我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<br />[2011-03-16 11:51:12,283][cylindro] ERROR:report:[24]:    if not str(value):]<br />从以上你贴出的log中可以看到在report_sxw.py模块的第251行用了str(value), 而这个value中应该有无法用ASCII编码的unicode字串(中文日期格式),str()默认使用ASCII来编码该字串从而导致错误。你可以试试用:<br />

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

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



  • Hi digitalsatori,<br /><br />结果是这样:<br /><br />[quote]<br />[2011-03-16 21:43:17,646][cylindro] ERROR:report:[16]: report :<br />[2011-03-16 21:43:17,646][cylindro] ERROR:report:[17]: Traceback (most recent call last):<br />[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<br />[2011-03-16 21:43:17,646][cylindro] ERROR:report:[19]:    txt = eval(expr,self.localcontext)<br />[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<br />[2011-03-16 21:43:17,647][cylindro] ERROR:report:[21]:    return eval(test_expr(expr,_SAFE_OPCODES, mode=mode), globals_dict, locals_dict)<br />[2011-03-16 21:43:17,647][cylindro] ERROR:report:[22]:  File "", line 1, in <module><br />[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<br />[2011-03-16 21:43:17,647][cylindro] ERROR:report:[24]:    return date.strftime(date_format)<br />[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)<br />[2011-03-16 21:43:17,647][cylindro] ERROR:report:[26]: <br />[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)<br />[2011-03-16 21:43:17,647][cylindro] ERROR:report:[28]: expr: formatLang(o.date_planned, date_time = True)<br />[/quote]<br /><br />strftime 不支持unicode 参数<br />


  • 管理员

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

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

    <br />



  • 先按校长说的,把str 改成 ustr,<br /><br />再按mrshelly说的,这样改:<br />

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

    <br />就行了<br /><br />出问题的原因是因为str和Python的strftime不支持Unicode.<br /><br />再次感谢两位的指导!<br /><br />Chip<br /><br /><br />