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

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

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

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

初学报表,不知从何处查错



  • 学习 把 社区这个模块 <br />http://openerp-china.org/index.php?page=developer<br /><br />加了一个简单的报表,结果这报表 ,死活出不来。<br /><br />求教大家从何下手查错。<br /><br /><br />lesson_view.xml<br />[code]<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 />[/code]<br /><br /><br />report_init_.py<br />[code]<br /># -- encoding: utf-8 --<br />import report<br />import oecn_training_lesson_report<br />[/code]<br /><br /><br />report\oecn_training_lesson_report.py<br />[code]<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 />[/code]<br /><br />report\oecn_training_lesson_report.rml<br />[code]<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 />[/code]<br /><br /><br />点击报表 菜单后直接就报错了<br />[code]<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 />[/code]<br /><br /><br /><br /><br /><br />server log 如下:<br /><br />[code]<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 />[/code]



  • 学习 把 社区这个模块 <br />http://openerp-china.org/index.php?page=developer<br /><br />加了一个简单的报表,结果这报表 ,死活出不来。<br /><br />求教大家从何下手查错。<br /><br /><br />lesson_view.xml<br />[code]<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 />[/code]<br /><br /><br />report_init_.py<br />[code]<br /># -- encoding: utf-8 --<br />import report<br />import oecn_training_lesson_report<br />[/code]<br /><br /><br />report\oecn_training_lesson_report.py<br />[code]<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 />[/code]<br /><br />report\oecn_training_lesson_report.rml<br />[code]<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 />[/code]<br /><br /><br />点击报表 菜单后直接就报错了<br />[code]<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 />[/code]<br /><br /><br /><br /><br /><br />server log 如下:<br /><br />[code]<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 />[/code]


  • 管理员

    感觉是你的报表没有注册到,是不是在report文件夹下的__init__.py没有import oecn_training_lesson_report?<br /><br />report_init_.py<br /><br />[code]# -- encoding: utf-8 --<br />import report<br />import oecn_training_lesson_report[/code]<br />为什么这里还要 import report? 这个import report 应该放在上一级的__init__.py里面吧<br />模块结构是怎样呢?<br /><br />



  • 跟踪代码看到的错误信息 确实是 报表没注册上去netsvc.LocalService('report.'+object)开始报错的<br /><br />我是在原来的教学模块 里依样画葫芦的 加了 报表。<br /><br />确实是  init.py 里面缺了 import report<br />弄错地方了。<br /><br /><br /><br /><br />改正后有进展,另外的错误了<br /><br />我继续 。。。。



  • 终于搞定 了,发现第二个错误,<br /><br />lesson_view.xml 中定义的 rml 路径和文件名错误,<br /><br />想不通为啥 要在两处(lesson_view.xml  和  report\oecn_training_lesson_report.py)都定义  rml  , 一样的东西,还希望高手们帮忙释疑


  • 管理员

    以你上面的代码为例:<br />[code]<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 />[/code]<br />这一段是在[url=http://www.openerp-china.org/index.php?page=ir.actions.report.xml]ir.actions.report.xml[/url]里添加一条记录,你可以通过进入 设定->自定义->底层对象->报表 可以查看到自己的报表<br /><br />[code]<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 />[/code]<br />这一段是实例化了report_sxw,实际上是通过这个实例来打印报表的。<br /><br />而你问的问题我们可以通过到report\report_sxw.py 代码里看看。<br />[code]<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 />[/code]<br />这里的主要意思是他首先会根据名字report_name搜索[url=http://www.openerp-china.org/index.php?page=ir.actions.report.xml]ir.actions.report.xml[/url],如果有匹配的就取它的记录,如果没有就用上面实例化的那个实例。<br />所以就是如果你向ir.actions.report.xml插入了报表数据 ,那么他就优先取它的数据而不是你在python里报表实例,这样的好处是你可以在openerp里面对报表直接进行修改(表头之类的),而不用修改代码。<br />欢迎测试


登录后回复
 

与 Odoo 中文社区 的连接断开,我们正在尝试重连,请耐心等待