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

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

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

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

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



  • 学习 把 社区这个模块
    http://openerp-china.org/index.php?page=developer

    加了一个简单的报表,结果这报表 ,死活出不来。

    求教大家从何下手查错。


    lesson_view.xml
    [code]
    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>
            <!--定义表单视图-->
            <record model="ir.ui.view" id="oecn_training_lesson_from_view">
                <field name="name">oecn.training.lesson.form</field>
                <field name="type">form</field>
                <field name="model">oecn.training.lesson</field>
                <field name="arch" type="xml">
                    <field name="name"/>
                    <field name="date_start"/>
                    <field name="total_day"/>
                    <field name="price"/>
                    <field name="teacher"/>
                    <field name="students" colspan="4"/>
                </field>
            </record>
            <!--定义列表视图-->
            <record model="ir.ui.view" id="oecn_training_lesson_tree_view">
                <field name="name">oecn.training.lesson.tree</field>
                <field name="type">tree</field>
                <field name="model">oecn.training.lesson</field>
                <field name="arch" type="xml">
                    <field name="name"/>
                    <field name="date_start"/>
                    <field name="teacher"/>
                    <field name="price" sum="合计"/>
                </field>
            </record>
            <!--定义视图动作-->
            <record model="ir.actions.act_window" id="action_oecn_training_lesson">
                <field name="name">oecn.training.lesson.action</field>
                <field name="res_model">oecn.training.lesson</field>
                <field name="view_type">form</field>
                <field name="view_mode">form,tree</field>
                <field name="view_id" ref="oecn_training_lesson_tree_view"/>
            </record>
            <!--定义菜单-->
            <menuitem id="oecn_menu" name="OECN"/>
            <menuitem id="oecn_training_menu" name="OECN Training" parent="oecn_menu"/>
            <menuitem id="oecn_training_lesson_menu" name="OECN training Lesson" parent="oecn_training_menu" action="action_oecn_training_lesson"/>
           
            <!-- Product_report 注释, 次文件定义报表的 ID 名称 菜单  对应 RML 文件 等等
    下面这部分是我自己加上去的
    -->
           
            <report
    auto="False"
    id="training_lesson_report"
    model="oecn.training.lesson"
    header="False"
    name="oecn.training.lesson_report"
    rml="oecn_training/report/oecn_training_lesson.rml"
                string="课程报告  Lesson report"
    />
           
       
        </data>
       
    </openerp>
    [/code]


    report_init_.py
    [code]
    # -- encoding: utf-8 --
    import report
    import oecn_training_lesson_report
    [/code]


    report\oecn_training_lesson_report.py
    [code]
    # -- encoding: utf-8 --
    import time
    from report import report_sxw
    from osv import osv

    class training_lesson_report(report_sxw.rml_parse):
        def init(self, cr, uid, name, context):
            super(training_lesson_report, self).init(cr, uid, name, context)
            self.localcontext.update({
                'time': time,
    'instructor': self._print_instructor,
            })

        def _print_instructor(self, seller_id):
            return 'Toto'

    report_sxw.report_sxw('report.oecn.training.lesson_report', 'oecn.training.lesson', 'addons/oecn_training_lesson/report/oecn_training_lesson_report.rml',
    parser=training_lesson_report)

    # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
    [/code]

    report\oecn_training_lesson_report.rml
    [code]
    <document filename="test.pdf">
      <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
        <pageTemplate id="first">
          <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
        </pageTemplate>
      </template>
      <stylesheet>
        <blockTableStyle id="Standard_Outline">
          <blockAlignment value="LEFT"/>
          <blockValign value="TOP"/>
        </blockTableStyle>
        <initialize>
          <paraStyle name="all" alignment="justify"/>
        </initialize>
        <paraStyle name="Standard" fontName="Times-Roman"/>
        <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
        <paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
        <paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
        <paraStyle name="Caption" fontName="Times-Roman" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
        <paraStyle name="Index" fontName="Times-Roman"/>
        <images/>
      </stylesheet>
      <story>
        <para style="Standard">Lesson information</para>
        <para style="Standard">[[repeatIn(objects,'o')]]</para>
        <para style="Standard">
          <font color="white"> </font>
        </para>
        <para style="Standard">Name: [[o.name or '']]</para>
      </story>
    </document>
    [/code]


    点击报表 菜单后直接就报错了
    [code]

    Client Traceback (most recent call last):
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\http.py", line 260, in dispatch
        r = method(controller, self, **self.params)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\controllers\main.py", line 1784, in index
        req.session._db, req.session._uid, req.session._password, report_id)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy
        result = self.connector.send(self.service_name, method, *args)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\http.py", line 596, in send
        fault = xmlrpclib.Fault('warning -- ' + e.name + '\n\n' + e.value, '')
    TypeError: coercing to Unicode: need string or buffer, tuple found

    [/code]





    server log 如下:

    [code]
    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 -
    2012-06-08 15:41:53,822 4620 ERROR ? openerp.service.web_services: Exception: u'report.oecn.training.lesson_report'
    Traceback (most recent call last):
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\service\web_services.py", line 709, in go
        obj = netsvc.LocalService('report.'+object)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\netsvc.py", line 94, in LocalService
        return Service._services[name]
    KeyError: u'report.oecn.training.lesson_report'
    2012-06-08 15:41:54,088 4620 ERROR ? openerp.netsvc: report.oecn.training.lesson_report
    (<type 'exceptions.KeyError'>, KeyError(u'report.oecn.training.lesson_report',), <traceback object at 0x06FDAE40>)

    [/code]



  • 学习 把 社区这个模块
    http://openerp-china.org/index.php?page=developer

    加了一个简单的报表,结果这报表 ,死活出不来。

    求教大家从何下手查错。


    lesson_view.xml
    [code]
    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>
            <!--定义表单视图-->
            <record model="ir.ui.view" id="oecn_training_lesson_from_view">
                <field name="name">oecn.training.lesson.form</field>
                <field name="type">form</field>
                <field name="model">oecn.training.lesson</field>
                <field name="arch" type="xml">
                    <field name="name"/>
                    <field name="date_start"/>
                    <field name="total_day"/>
                    <field name="price"/>
                    <field name="teacher"/>
                    <field name="students" colspan="4"/>
                </field>
            </record>
            <!--定义列表视图-->
            <record model="ir.ui.view" id="oecn_training_lesson_tree_view">
                <field name="name">oecn.training.lesson.tree</field>
                <field name="type">tree</field>
                <field name="model">oecn.training.lesson</field>
                <field name="arch" type="xml">
                    <field name="name"/>
                    <field name="date_start"/>
                    <field name="teacher"/>
                    <field name="price" sum="合计"/>
                </field>
            </record>
            <!--定义视图动作-->
            <record model="ir.actions.act_window" id="action_oecn_training_lesson">
                <field name="name">oecn.training.lesson.action</field>
                <field name="res_model">oecn.training.lesson</field>
                <field name="view_type">form</field>
                <field name="view_mode">form,tree</field>
                <field name="view_id" ref="oecn_training_lesson_tree_view"/>
            </record>
            <!--定义菜单-->
            <menuitem id="oecn_menu" name="OECN"/>
            <menuitem id="oecn_training_menu" name="OECN Training" parent="oecn_menu"/>
            <menuitem id="oecn_training_lesson_menu" name="OECN training Lesson" parent="oecn_training_menu" action="action_oecn_training_lesson"/>
           
            <!-- Product_report 注释, 次文件定义报表的 ID 名称 菜单  对应 RML 文件 等等
    下面这部分是我自己加上去的
    -->
           
            <report
    auto="False"
    id="training_lesson_report"
    model="oecn.training.lesson"
    header="False"
    name="oecn.training.lesson_report"
    rml="oecn_training/report/oecn_training_lesson.rml"
                string="课程报告  Lesson report"
    />
           
       
        </data>
       
    </openerp>
    [/code]


    report_init_.py
    [code]
    # -- encoding: utf-8 --
    import report
    import oecn_training_lesson_report
    [/code]


    report\oecn_training_lesson_report.py
    [code]
    # -- encoding: utf-8 --
    import time
    from report import report_sxw
    from osv import osv

    class training_lesson_report(report_sxw.rml_parse):
        def init(self, cr, uid, name, context):
            super(training_lesson_report, self).init(cr, uid, name, context)
            self.localcontext.update({
                'time': time,
    'instructor': self._print_instructor,
            })

        def _print_instructor(self, seller_id):
            return 'Toto'

    report_sxw.report_sxw('report.oecn.training.lesson_report', 'oecn.training.lesson', 'addons/oecn_training_lesson/report/oecn_training_lesson_report.rml',
    parser=training_lesson_report)

    # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
    [/code]

    report\oecn_training_lesson_report.rml
    [code]
    <document filename="test.pdf">
      <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
        <pageTemplate id="first">
          <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
        </pageTemplate>
      </template>
      <stylesheet>
        <blockTableStyle id="Standard_Outline">
          <blockAlignment value="LEFT"/>
          <blockValign value="TOP"/>
        </blockTableStyle>
        <initialize>
          <paraStyle name="all" alignment="justify"/>
        </initialize>
        <paraStyle name="Standard" fontName="Times-Roman"/>
        <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
        <paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
        <paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
        <paraStyle name="Caption" fontName="Times-Roman" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
        <paraStyle name="Index" fontName="Times-Roman"/>
        <images/>
      </stylesheet>
      <story>
        <para style="Standard">Lesson information</para>
        <para style="Standard">[[repeatIn(objects,'o')]]</para>
        <para style="Standard">
          <font color="white"> </font>
        </para>
        <para style="Standard">Name: [[o.name or '']]</para>
      </story>
    </document>
    [/code]


    点击报表 菜单后直接就报错了
    [code]

    Client Traceback (most recent call last):
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\http.py", line 260, in dispatch
        r = method(controller, self, **self.params)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\controllers\main.py", line 1784, in index
        req.session._db, req.session._uid, req.session._password, report_id)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy
        result = self.connector.send(self.service_name, method, *args)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\addons\web\common\http.py", line 596, in send
        fault = xmlrpclib.Fault('warning -- ' + e.name + '\n\n' + e.value, '')
    TypeError: coercing to Unicode: need string or buffer, tuple found

    [/code]





    server log 如下:

    [code]
    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 -
    2012-06-08 15:41:53,822 4620 ERROR ? openerp.service.web_services: Exception: u'report.oecn.training.lesson_report'
    Traceback (most recent call last):
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\service\web_services.py", line 709, in go
        obj = netsvc.LocalService('report.'+object)
      File "D:\3lp\studio\OpenERP\source6.1\server\openerp\netsvc.py", line 94, in LocalService
        return Service._services[name]
    KeyError: u'report.oecn.training.lesson_report'
    2012-06-08 15:41:54,088 4620 ERROR ? openerp.netsvc: report.oecn.training.lesson_report
    (<type 'exceptions.KeyError'>, KeyError(u'report.oecn.training.lesson_report',), <traceback object at 0x06FDAE40>)

    [/code]


  • 管理员

    感觉是你的报表没有注册到,是不是在report文件夹下的__init__.py没有import oecn_training_lesson_report?

    report_init_.py

    [code]# -- encoding: utf-8 --
    import report
    import oecn_training_lesson_report[/code]
    为什么这里还要 import report? 这个import report 应该放在上一级的__init__.py里面吧
    模块结构是怎样呢?



  • 跟踪代码看到的错误信息 确实是 报表没注册上去netsvc.LocalService('report.'+object)开始报错的

    我是在原来的教学模块 里依样画葫芦的 加了 报表。

    确实是  init.py 里面缺了 import report
    弄错地方了。




    改正后有进展,另外的错误了

    我继续 。。。。



  • 终于搞定 了,发现第二个错误,

    lesson_view.xml 中定义的 rml 路径和文件名错误,

    想不通为啥 要在两处(lesson_view.xml  和  report\oecn_training_lesson_report.py)都定义  rml  , 一样的东西,还希望高手们帮忙释疑


  • 管理员

    以你上面的代码为例:
    [code]
    <report
                auto="False"
                id="training_lesson_report"
                model="oecn.training.lesson"
                header="False"
                name="oecn.training.lesson_report"
                rml="oecn_training/report/oecn_training_lesson.rml"
                string="课程报告  Lesson report"
            />
    [/code]
    这一段是在[url=http://www.openerp-china.org/index.php?page=ir.actions.report.xml]ir.actions.report.xml[/url]里添加一条记录,你可以通过进入 设定->自定义->底层对象->报表 可以查看到自己的报表

    [code]
    report_sxw.report_sxw('report.oecn.training.lesson_report', 'oecn.training.lesson', 'addons/oecn_training_lesson/report/oecn_training_lesson_report.rml',
    parser=training_lesson_report)
    [/code]
    这一段是实例化了report_sxw,实际上是通过这个实例来打印报表的。

    而你问的问题我们可以通过到report\report_sxw.py 代码里看看。
    [code]
            ir_obj = pool.get('ir.actions.report.xml')
            report_xml_ids = ir_obj.search(cr, uid,
                    [('report_name', '=', self.name[7:])], context=context)
            if report_xml_ids:
                report_xml = ir_obj.browse(cr, uid, report_xml_ids[0], context=context)
            else:
                title = ''
                report_file = tools.file_open(self.tmpl, subdir=None)
                try:
                    rml = report_file.read()
                    report_type= data.get('report_type', 'pdf')
                    class a(object):
                        def init(self, *args, **argv):
                            for key,arg in argv.items():
                                setattr(self, key, arg)
                    report_xml = a(title=title, report_type=report_type, report_rml_content=rml, name=title, attachment=False, header=self.header)
                finally:
                    report_file.close()
    [/code]
    这里的主要意思是他首先会根据名字report_name搜索[url=http://www.openerp-china.org/index.php?page=ir.actions.report.xml]ir.actions.report.xml[/url],如果有匹配的就取它的记录,如果没有就用上面实例化的那个实例。
    所以就是如果你向ir.actions.report.xml插入了报表数据 ,那么他就优先取它的数据而不是你在python里报表实例,这样的好处是你可以在openerp里面对报表直接进行修改(表头之类的),而不用修改代码。
    欢迎测试


登录后回复
 

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