以你上面的代码为例:
<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里面对报表直接进行修改(表头之类的),而不用修改代码。
欢迎测试