• openerp经典收藏 深入理解报表运行机制(转载)


    深入理解报表运行机制

    原文:http://blog.sina.com.cn/s/blog_57ded94e01014ppd.html

    1) OpenERP报表的基本运行机制
        OpenERP报表的一般定义语法是:
          <report id="c2c_demo_report_x" string="C2C Demo Report" model="hr.holidays" 
              name="sandbox_c2c_reporting_tools" header="False"/>

    这个定义的含义是,在对象hr.holidays上增加报表操作(model="hr.holidays"),该报表操作的显示字符是C2C Demo Report(string="C2C Demo Report"),当用户点击该操作字符(C2C Demo Report),系统调用名为sandbox_c2c_reporting_tools(name="sandbox_c2c_reporting_tools")的Services,该Services返回报表文件(PDF或其他格式文件)。
        因此,理解OpenERP报表机制的核心是,理解报表Services机制。

    2) OpenERP的报表Service
        OpenERP的报表Service的基本接口定义在文件:openerp-server-6.0.3in eportinterface.py,期定义如下:
            report_int(netsvc.Service)
              __init__(self, name, audience='*')
              create(self, cr, uid, ids, datas, context=None)

        init方法中最重要的参数是name,该参数是Service Name,其格式是"report.xxx", xxx 必须和报表定义时候的(name="sandbox_c2c_reporting_tools")一致,系统是通过该名字找到该Service。
        create方法中,最重要的参数是ids,该参数是报表操作所在的画面上,选定的对象的id列表。通常,系统会为ids中的每一个对象出一个报表。datas参数通常用于Wizard的情况,即先弹出Wizard画面,用户输入一些数据,点击按钮,系统再输出报表文件。在这种情况,datas参数里保存着用户在Wizard画面上输入的数据。
        显然,系统的内部动作是,用户点击报表动作,系统根据name="sandbox_c2c_reporting_tools"找到相应Service,调用Service的Create方法,返回报表文件。Create方法的返回值格式是:(report_doc,mimetype)。例如,如果返回pdf报表,返回值是(pdf_doc,'pdf')。

    3) RML报表
        如果直接继承接口report_int,编写create方法生成pdf文档,代码复杂,工作量大。系统提供了RML格式报表,用于简化pdf报表开发。其基本原理是,开发RML格式文档,系统的Create方法读取rml文件,渲染成pdf文档,输出。相关接口如下:
      report_rml(report_int)
        __init__(self, name, table, tmpl, xsl)
        create(self, cr, uid, ids, datas, context)

      report_sxw(report_rml)
        __init__(self, name, table, rml=False, parser=rml_parse, header='external', store=False)
        create(self, cr, uid, ids, data, context=None)

        这两个派生Class中,create方法的参数没有变化,init方法增加了一些参数,说明如下:
        table: 报表关联的数据对象,渲染rml时候需要调用该对象取得数据。
        rml:RML文件路径及名称,系统需要读取该文件渲染成PDF报表。
        parser:渲染器,系统的实际做法是,在create方法中调用渲染器的有关方法,将rml渲染成pdf。用户可以开发自己的渲染器,用于将rml渲染成其他格式,如html、txt等,实际上,系统已经提供了html、txt等的渲染器。

        因此,开发rml格式的报表时候,通常只需要开发自己的渲染器(parser),不需要开发report_int。

  • 相关阅读:
    hive_学习_00_资源帖
    大数据_学习_02_目录贴_大数据学习总结
    hadoop_异常_02_ExitCodeException exitCode=1: chmod: changing permissions of `/ray/hadoop/dfs/data': Operation not permitted
    hbase_异常_05_End of File Exception between local host is: "rayner/127.0.1.1"; destination host is: "localhost":9000;
    hbase_异常_04_util.FSUtils: Waiting for dfs to exit safe mode...
    hbase_异常_03_java.io.EOFException: Premature EOF: no length prefix available
    hbase_异常_02_hbase无法访问16010端口
    hbase_异常_01_Hbase: Failed to become active master
    【HDU】2147 kiki's game
    【HDU】1517 A Multiplication Game
  • 原文地址:https://www.cnblogs.com/cnshen/p/3189185.html
Copyright © 2020-2023  润新知