以模块oecnj_trainning为例,模块路径: ~/openerp/addons/oecn_training/ ,以下简写为 path/oecn/

Report生成方法:(手写) rml + reportlab生成.

实践步骤:

1. 在 path/oecn/oecn_report.xml ,
<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <report
                id="report_oecn_training_lesson" # 标签 id
                name="oecn.lesson" # 标签名称, 是下文中oecn_print.py中的 "'report.oecn.lesson"中除去前面report.的部分.
                model="oecn.training.lesson" # 标签匹配的model
                rml="oecn_training/report/oecn_report.xml" # 使用到的 rml 文件
                string="打印课程" # 客户端上 显示此报表 的对应菜单的文本
                header="False" # 是否在本报表中显示公司统一的表头和表尾
                auto="False" />
    </data>
</openerp>

2. 在 path/oecn/__openerp__.py, 注意update_xml的值
# -*- coding: utf-8 -*-
{
        "name" : "OECN Training", #模块名
    "version" : "1.0", #模块版本
    "description" : 'OECN Training Demo', #模块说明
    "author" : "Shine IT", #作者
    "website" : "http://www.openerp.cn", #网址
    "depends" : [], #依赖的模块
    "update_xml" : ["lesson_view.xml",
                                        "lesson_report.xml",
                                        "report/oecn_report.rml"
        ], #模块更新的时候会读入的文件
    "installable" : True, #可否安装
    "category":'Generic Modules/Others' #模块类型
}

3. 新增path/oecn/report/ 文件夹, 其下有 __init__.py, oecn_print.py, oecn_report.rml 文件,
 3.1) __init__.py:
  import oecn_print

3.2) oecn_print.py:
import time
from openerp.report import report_sxw

# rml parser 类
class rpt_oecn_training_lesson(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(rpt_oecn_training_lesson, self).__init__(cr, uid, name, context)
        self.localcontext.update({"time": time,})
        
report_sxw.report_sxw('report.oecn.lesson', # 对象的内部名字,可以任意取, 以"report."开头
                      'oecn.training.lesson', # 与报表想关联的对象(model),报表数据通过该对象访问.
                      'addons/oecn_training/report/oecn_report.rml', # 与报表关联的RML文件名及路径.
                      parser=rpt_oecn_training_lesson, # 解析rml文件的对象。
                      header=False) # 表示要不要在本报表中显示公司统一的表头和表尾。

3.3) oecn_report.rml , <template> 标签下必须对页面进行设置,否则在OpenERP运行会报错。
<?xml version="1.0" encoding="utf-8" standalone="no" ?>

<document filename="report.pdf">
    <!-- 报表页面设置 -->
    <template>
        <pageTemplate id="main">
            <frame id="first" x1="72" y1="72" width="451" height="698"/>
        </pageTemplate>
    </template>
    
    <!-- 报表页面样式设置 -->
    <stylesheet>
        <paraStyle name="Standard" fontName="Helvetica" fontSize="14.0" leading="16.0" alignment="CENTER" />
    </stylesheet>
    
    <!-- 报表页面正文-->
    <story>
        <para>[ repeatIn(objects,'o') ]</para>
        <para style="Standard">介绍</para>
        <para style="Standard">[ o.name ]</para>
    </story>
</document>

note:
 将 repeatIn( ) 放在 <section> tag 下,内容迭代不分页
 将 repeatIn( ) 放在 <story> tag 下,内容迭代分页
测试发现,objects 参数 必须在 <story>下,不然会报错。

4. 升级该模块, 就可以打印report。 由于 OpenERP 对中文支持不够, 输出的pdf文档会显示为黑块。 安装第三方模块oecn_base_fonts(安装说明)即可解决中文打印的问题:

最新文章

  1. 使用tomact监控应用服务器的性能
  2. [多校联考2 T3] 排列 (DP)
  3. linux 下搭建 storm
  4. How to remove replication in SyteLine V2
  5. IE6不支持CSS的属性选择器
  6. Filezilla Server 配置大全
  7. [反汇编练习] 160个CrackMe之015
  8. 17173php招聘
  9. MySQL数据库索引简介
  10. DS博客作业01--日期抽象数据类型设计与实现
  11. [我的理解]Javascript的原型与原型链
  12. Python3.6 提示 ModuleNotFoundError: No module named &#39;_ssl&#39; 模块问题
  13. 【凡尘】---react-redux---【react】
  14. git --- 持续更新
  15. webView 获取内容高度不准确的原因是因为你设置了某个属性
  16. 什么是HDFS
  17. 网络传输--TCP
  18. AUC和ROC
  19. RMAN常用命令汇总!
  20. php提交表单校验例子

热门文章

  1. SPOJ 3267. D-query (主席树,查询区间有多少个不相同的数)
  2. BZOJ 1500: [NOI2005]维修数列 (splay tree)
  3. Namespace declaration statement has to be the very first statement in the script
  4. 探秘C#中的yield关键字
  5. 7. python 字符串格式化方法(2)
  6. Java Web开发基础(2)-JSP
  7. MyBatis的动态SQL详解-各种标签使用
  8. 解决Sqoop报错Could not load db driver class: com.intersys.jdbc.CacheDriver
  9. Ubuntu 12.04 安装配置 Apache2
  10. go语言基础之go猜数字游戏