Jalena Blog

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

Odoo 打印开发

2018-07-12

声明报告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)
标签: odoo report
最后更新:2019-01-01

Jalena

原创内容,转载请注明出处! 部分内容来自网络,请遵守法律适用!

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

【腾讯云】云服务器特惠热卖中
文章目录
  • 声明报告Actions
  • 定义纸张
  • 定义模板
  • 自定义报告
标签聚合
java Centos odoo 其他 生活 wordpress docker MySql
分类
  • Android / 4篇
  • C# / 10篇
  • Codec / 9篇
  • Conversion / 14篇
  • Editing / 16篇
  • Java / 47篇
  • Javascript / 3篇
  • Linux / 30篇
  • Odoo / 25篇
  • Python / 6篇
  • SQL / 30篇
  • Web / 3篇
  • Windows / 4篇
  • 我的日记 / 10篇
  • 杂七杂八 / 93篇
  • 软件开发 / 72篇
  • 非线性编辑 / 1篇

COPYRIGHT © 2026 Jalena Blog. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蜀ICP备17025376号