初学报表,不知从何处查错
-
学习 把 社区这个模块 <br / [检测到链接无效,已移除] br />
加了一个简单的报表,结果这报表 ,死活出不来。
求教大家从何下手查错。
lesson_view.xml<br /><?xml version="1.0" encoding="utf-8"?><br /><openerp><br /> <data><br /> <!--定义表单视图--><br /> <record model="ir.ui.view" id="oecn_training_lesson_from_view"><br /> <field name="name">oecn.training.lesson.form</field><br /> <field name="type">form</field><br /> <field name="model">oecn.training.lesson</field><br /> <field name="arch" type="xml"><br /> <field name="name"/><br /> <field name="date_start"/><br /> <field name="total_day"/><br /> <field name="price"/><br /> <field name="teacher"/><br /> <field name="students" colspan="4"/><br /> </field><br /> </record><br /> <!--定义列表视图--><br /> <record model="ir.ui.view" id="oecn_training_lesson_tree_view"><br /> <field name="name">oecn.training.lesson.tree</field><br /> <field name="type">tree</field><br /> <field name="model">oecn.training.lesson</field><br /> <field name="arch" type="xml"><br /> <field name="name"/><br /> <field name="date_start"/><br /> <field name="teacher"/><br /> <field name="price" sum="合计"/><br /> </field><br /> </record><br /> <!--定义视图动作--><br /> <record model="ir.actions.act_window" id="action_oecn_training_lesson"><br /> <field name="name">oecn.training.lesson.action</field><br /> <field name="res_model">oecn.training.lesson</field><br /> <field name="view_type">form</field><br /> <field name="view_mode">form,tree</field><br /> <field name="view_id" ref="oecn_training_lesson_tree_view"/><br /> </record><br /> <!--定义菜单--><br /> <menuitem id="oecn_menu" name="OECN"/><br /> <menuitem id="oecn_training_menu" name="OECN Training" parent="oecn_menu"/><br /> <menuitem id="oecn_training_lesson_menu" name="OECN training Lesson" parent="oecn_training_menu" action="action_oecn_training_lesson"/><br /> <br /> <!-- Product_report 注释, 次文件定义报表的 ID 名称 菜单 对应 RML 文件 等等 <br /> 下面这部分是我自己加上去的 <br /> --><br /> <br /> <report <br /> auto="False" <br /> id="training_lesson_report" <br /> model="oecn.training.lesson" <br /> header="False" <br /> name="oecn.training.lesson_report" <br /> rml="oecn_training/report/oecn_training_lesson.rml" <br /> string="课程报告 Lesson report"<br /> /><br /> <br /> <br /> </data><br /> <br /></openerp><br />
report_init_.py<br /># -*- encoding: utf-8 -*-<br />import report<br />import oecn_training_lesson_report<br />
report\oecn_training_lesson_report.py<br /># -*- encoding: utf-8 -*-<br />import time<br />from report import report_sxw<br />from osv import osv<br /> <br />class training_lesson_report(report_sxw.rml_parse):<br /> def __init__(self, cr, uid, name, context):<br /> super(training_lesson_report, self).__init__(cr, uid, name, context)<br /> self.localcontext.update({<br /> 'time': time,<br /> 'instructor': self._print_instructor,<br /> })<br /><br /> def _print_instructor(self, seller_id):<br /> return 'Toto'<br /><br />report_sxw.report_sxw('report.oecn.training.lesson_report', 'oecn.training.lesson', 'addons/oecn_training_lesson/report/oecn_training_lesson_report.rml',<br />parser=training_lesson_report)<br /> <br /># vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:<br />
report\oecn_training_lesson_report.rml<br /><document filename="test.pdf"><br /> <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20"><br /> <pageTemplate id="first"><br /> <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/><br /> </pageTemplate><br /> </template><br /> <stylesheet><br /> <blockTableStyle id="Standard_Outline"><br /> <blockAlignment value="LEFT"/><br /> <blockValign value="TOP"/><br /> </blockTableStyle><br /> <initialize><br /> <paraStyle name="all" alignment="justify"/><br /> </initialize><br /> <paraStyle name="Standard" fontName="Times-Roman"/><br /> <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/><br /> <paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/><br /> <paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/><br /> <paraStyle name="Caption" fontName="Times-Roman" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/><br /> <paraStyle name="Index" fontName="Times-Roman"/><br /> <images/><br /> </stylesheet><br /> <story><br /> <para style="Standard">Lesson information</para><br /> <para style="Standard">[[repeatIn(objects,'o')]]</para><br /> <para style="Standard"><br /> <font color="white"> </font><br /> </para><br /> <para style="Standard">Name: [[o.name or '']]</para><br /> </story><br /></document><br />
点击报表 菜单后直接就报错了<br /><br />Client Traceback (most recent call last):<br /> File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\http.py", line 260, in dispatch<br /> r = method(controller, self, **self.params)<br /> File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\controllers\main.py", line 1784, in index<br /> req.session._db, req.session._uid, req.session._password, report_id)<br /> File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy<br /> result = self.connector.send(self.service_name, method, *args)<br /> File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\http.py", line 596, in send<br /> fault = xmlrpclib.Fault('warning -- ' + e.name + '\n\n' + e.value, '')<br />TypeError: coercing to Unicode: need string or buffer, tuple found<br /><br />
server log 如下:<br />2012-06-08 15:41:53,651 4620 INFO ? werkzeug: 127.0.0.1 - - [08/Jun/2012 15:41:53] "POST /web/session/eval_domain_and_context HTTP/1.1" 200 -<br />2012-06-08 15:41:53,822 4620 ERROR ? openerp.service.web_services: Exception: u'report.oecn.training.lesson_report'<br />Traceback (most recent call last):<br /> File "D:\3lp\studio\OpenERP\source6.1\server\openerp\service\web_services.py", line 709, in go<br /> obj = netsvc.LocalService('report.'+object)<br /> File "D:\3lp\studio\OpenERP\source6.1\server\openerp\netsvc.py", line 94, in LocalService<br /> return Service._services[name]<br />KeyError: u'report.oecn.training.lesson_report'<br />2012-06-08 15:41:54,088 4620 ERROR ? openerp.netsvc: report.oecn.training.lesson_report<br />(<type 'exceptions.KeyError'>, KeyError(u'report.oecn.training.lesson_report',), <traceback object at 0x06FDAE40>)<br /><br />
-
以你上面的代码为例:
<br /><report <br /> auto="False" <br /> id="training_lesson_report" <br /> model="oecn.training.lesson" <br /> header="False" <br /> name="oecn.training.lesson_report" <br /> rml="oecn_training/report/oecn_training_lesson.rml" <br /> string="课程报告 Lesson report"<br /> /><br />
这一段是在 [检测到链接无效,已移除] 里添加一条记录,你可以通过进入 设定->自定义->底层对象->报表 可以查看到自己的报表<br />report_sxw.report_sxw('report.oecn.training.lesson_report', 'oecn.training.lesson', 'addons/oecn_training_lesson/report/oecn_training_lesson_report.rml',<br />parser=training_lesson_report)<br />
这一段是实例化了report_sxw,实际上是通过这个实例来打印报表的。
而你问的问题我们可以通过到report\report_sxw.py 代码里看看。<br /> ir_obj = pool.get('ir.actions.report.xml')<br /> report_xml_ids = ir_obj.search(cr, uid,<br /> [('report_name', '=', self.name[7:])], context=context)<br /> if report_xml_ids:<br /> report_xml = ir_obj.browse(cr, uid, report_xml_ids[0], context=context)<br /> else:<br /> title = ''<br /> report_file = tools.file_open(self.tmpl, subdir=None)<br /> try:<br /> rml = report_file.read()<br /> report_type= data.get('report_type', 'pdf')<br /> class a(object):<br /> def __init__(self, *args, **argv):<br /> for key,arg in argv.items():<br /> setattr(self, key, arg)<br /> report_xml = a(title=title, report_type=report_type, report_rml_content=rml, name=title, attachment=False, header=self.header)<br /> finally:<br /> report_file.close()<br />
这里的主要意思是他首先会根据名字report_name搜索 [检测到链接无效,已移除] ,如果有匹配的就取它的记录,如果没有就用上面实例化的那个实例。
所以就是如果你向ir.actions.report.xml插入了报表数据 ,那么他就优先取它的数据而不是你在python里报表实例,这样的好处是你可以在openerp里面对报表直接进行修改(表头之类的),而不用修改代码。
欢迎测试