<report id="c2c_demo_report_x" string="C2C Demo Report" model="hr.holidays" name="sandbox_c2c_reporting_tools" auto="False" 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 机制。
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')。
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 方法增加了一些参数,说明如下: