中文生产单打印,日期项不能打印
-
[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]
不是报表模板的问题,报表模板没有动过
新安装,什么也不做,就会这样 -
我这样弄的:
<br /> dt_text = unicode( self.lang_obj.date_format+ " " + self.lang_obj.time_format, 'utf-8' )<br /> 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('utf8')