以模块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(安装说明)即可解决中文打印的问题:

【OpenERP】Report 生成的更多相关文章

  1. OpenERP report doesn't work

    1. When you have used OpenOffice edited  one of reports,it has stored the report's banary data is da ...

  2. openerp report image

    webkit : 再mako 文件中插入以下代码, <% %>标签用于再mako中定义代码或者函数. 然后  ${ embed_image('图片类型', 图片字段 , 宽度,高度)  } ...

  3. Beyond Compare 命令行生成目录下所有文件比对的Html网页report

    MAC环境下,使用Beyond Compare命令行生成两个文件夹差异的html,按目录递归生成. #1. 创建compare #2. 创建compare/old #3. compare/new #4 ...

  4. openerp 经典收藏 Openerp开发进销存系统完毕总结(转载)

    原文地址:http://blog.csdn.net/heartrude/article/details/9142463 Openerp开发进销存系统完毕总结 分类: 代码历程 OpenERP 工程思想 ...

  5. Openerp 添加修改报表

    Report Designer 模块在生成新报表的时候是有BUG的不建议直接使用,不过我们也可以通过该插件再写简单的代码来实现新添加报表,插件安装成功后我们可以按照下列方法来添加报表 OpenERP ...

  6. Openerp开发进销存系统完毕总结

      转自:http://blog.csdn.net/heartrude/article/details/9142463 安装Openoffice 在openoffice中安装openerp repor ...

  7. Openerp开发进销存系统总结

    转自 :http://blog.sina.com.cn/s/blog_7cb52fa80101ngt8.html 差不多用了2个星期的闲余事件,对于openerp v7.0进行了学习和应用开发.细节总 ...

  8. jmeter生成html格式接口自动化测试报告

    jmeter生成html格式接口自动化测试报告 jmeter自带执行结果查看的插件,但是需要在jmeter工具中才能查看,如果要向领导提交测试结果,不够方便直观. 笔者刚做了这方面的尝试,总结出来分享 ...

  9. java生成word的几种方案

    http://blog.sina.com.cn/s/blog_a5e968370101crtl.html 1. Jacob是Java-COM Bridge的缩写,它在Java与微软的COM组件之间构建 ...

随机推荐

  1. 信用卡:银联,VISA,MasterCard

    国际信用卡是一种银行联合国际信用卡组织签发给那些资信良好的人士并可以在全球范围内进行透支消费的卡片,同时该卡也被用于在国际网络上确认用户的身份. 国际发卡组织是一个由全世界银行参与的非营利的国际性组织 ...

  2. +5v to +13v Converter

    http://www.romanblack.com/smps/conv.htm What is it?  This is a simple smps voltage converter, it mak ...

  3. PHP-系统流程

    我们来系统的了解下ThinkPHP框架开发的应用的标准执行流程: 用户URL请求 调用应用入口文件(通常是网站的index.php) 载入框架入口文件(ThinkPHP.php) 记录初始运行时间和内 ...

  4. [转载] MATLAB快捷键

    原文地址,点此查看 一.常用对象操作 除了一般windows窗口的常用功能键外. 1.!dir 可以查看当前工作目录的文件. !dir& 可以在dos状态下查看. 2.who   可以查看当前 ...

  5. 如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)

      如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)1.首先要下载我提供的软件包(里面已经包含所有所需软件); 2.把它解压到D盘根目录下(如果需要安装在其它的地方,请注意设好路径); ...

  6. maven项目如何生成war文件

    配置 你的pom.xml文件,在你的overview视窗里 配置 packaging为 war 然后然后点击 pom.xml右键,run as 选择 install 或是 package如果项目没问题 ...

  7. 分享JavaScript获取网页关闭与取消关闭的事件

    在做Web开发时,我们经常用到页面关闭事件onbeforeunload,可以给用户一个选择放弃关闭的机会,就比如这个博客编辑器.如果用户选择了离开,那么onunload事件自然会触发:但若用户选择了取 ...

  8. eclipse3.4配置的tomcat server如何部署以前的web项目?

    1. 打开.project文件,在<natures>元素中加入 <nature>org.eclipse.wst.common.project.facet.core.nature ...

  9. IDEA的注册

    步骤: license server -> 属性 -> 允许作为程序执行文件 即 chmod 777

  10. 页面元素定位 XPath 简介

    页面元素定位 XPath 简介 本文所说的 Xpath 是用于 Selenium 自动化测试所使用到的,是针对XHTML网页而言的一种页面元素的定位表示法. XPath 背景 XPath即为XML路径 ...