Jalena Blog

  • 首页
  • 程序开发
    • Java
    • Spring
    • SpringBoot
    • SpringMvc
    • Python
    • Odoo
    • C#
    • SQL
    • Web
    • Linux
  • 移动设备
    • Android
    • BlackBerry
    • Router
  • 杂七杂八
    • 我的废话
    • 音频
    • 视频
    • 常用软件
  • 关于
A bad workman always blames his tools.
  1. 首页
  2. Development
  3. Python
  4. Odoo
  5. 正文

Odoo 打印开发

2018年07月12日 245点热度 0人点赞 0条评论

声明报告Actions

参考链接:QWeb Reports

<report
        id="budget_report"
        model="budget.budget"
        report_type="qweb-pdf"
        string="Budget Report"
        name="contract_manager.budget_report_template"
        file="contract_manager.budget_report_template"
        paperformat="budget_print_format"
        menu="True"
/>

定义纸张

参考链接:Paper Format

<record id="budget_print_format" model="report.paperformat">
	<field name="name">Budget Print format</field>
	<field name="format">A4</field>
	<field name="orientation">Landscape</field> <!--方向-->
	<field name="margin_top">3</field>
	<field name="margin_bottom">3</field>
	<field name="margin_left">3</field>
	<field name="margin_right">3</field>
	<field name="header_line" eval="False" />
	<field name="header_spacing">3</field>
	<field name="dpi">90</field>
</record>

定义模板

<template id="report_invoice">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="report.external_layout">
                <div class="page">
                    <h2>Report title</h2>
                    <p>This object's name is <span t-field="o.name"/></p>
                </div>
            </t>
        </t>
    </t>
</template>

调用report.external_layout将在报告上添加默认的页眉和页脚,正文将是其中的<div class="page">

报告中可以访问的一些特定变量,主要是:

  • docs  当前报告的数据记录集
  • doc_ids 记录的id列表
  • doc_model docs记录的模型
  • time 来自Python标准库的引用
  • user res.user用户打印报告的记录
  • res_company 当前user的公司

自定义报告

使用自定义报告需要具有一个默认的 get_html 函数,如果你希望在模板中包含更多的内容(例如,其他模型记录)来自定义报告,则可以定义此模型,覆盖函数并在字典中传递对象: report.module.report_name render_html docargs

from odoo import api, models

class ParticularReport(models.AbstractModel):
    _name = 'report.module.report_name'
    @api.model
    def render_html(self, docids, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name('module.report_name')
        docargs = {
            'doc_ids': docids,
            'doc_model': report.model,
            'docs': self,
        }
        return report_obj.render('module.report_name', docargs)
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: odoo report
最后更新:2019年01月01日

Jalena

A bad workman always blames his tools.

点赞
< 上一篇
下一篇 >

文章评论

取消回复

Jalena

A bad workman always blames his tools.

最新 热点 随机
最新 热点 随机
Centos 7 离线安装Nginx Centos nmcli 网络管理命令 Linux 密钥登录 服务器部署vSphere ESXI 软路由(ESXi)安装OpenWrt 使用 Docker 部署 wordpress Android Studio Gradle 代理设置 Frp 反向代理 Git 更新合并fork的项目代码 MySQL 常用命令
Centos nmcli 网络管理命令Centos 7 离线安装Nginx
什么是递归? Centos7 部署 Odoo10.0 生产环境 剪辑与剪辑艺术 Centos/Mac 命令自动补全 JAVA 输出任意奇数的菱形 音乐 - 假如爱有天意 Centos 6.x安装denyhosts阻止恶意破解SSH Mybatis 插入或更新数据 Git 使用密钥登陆服务 Canopus DV Codec 1.00
标签聚合
wordpress 生活 Centos 解码 java Edius odoo 其他
Links
  • Emin.ink
  • 时空镜像
  • ZWWoOoOo
  • ninja911
  • 猿人学网站
  • Feng Blog

COPYRIGHT © 2020 Jalena Blog. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS