分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

odoo10学习笔记十三:qweb报表

发布时间:2023-09-06 01:35责任编辑:傅花花关键词:暂无标签

原文地址:http://www.cnblogs.com/ygj0930/p/7151732.html

一:概述

报表是使用qweb定义的,报表的pdf导出是使用wkhtmltopdf来完成的。

如果需要为一个模型创建报表,需要定义report及对应模板

如果有需要的话还可以指定特定的纸张格式

如果需要访问其他模型,就需要定义Custom Report。

二:Report

report标签可用于定义一个报表:

id - 生成的数据的idname (必选) - 报表名用于查找及描述model (必选) - 报表所对应的模型report_type (必选) - qweb-pdf: pdf | qweb-html : htmlreport_name - 输出pdf时文件名groups - Many2many字段用于指定可以查看使用该报表的用户组attachment_use - 如果设置为true时,该报表会以记录的附件的形式保存,一般用于一次生成多次使用的报表attachment - 用于定义报表名的python表达式,记录可以通过object对象访问paperformat - 用于打印报表的文件格式的外部id(默认是公司的格式)(可以自定义格式)
<report ???id="account_invoices" ???model="account.invoice" ???string="Invoices" ???report_type="qweb-pdf" ???name="account.report_invoice" ???file="account.report_invoice" ???attachment_use="True" ???attachment="(object.state in (‘open‘,‘paid‘)) and ???????(‘INV‘+(object.number or ‘‘).replace(‘/‘,‘‘)+‘.pdf‘)" //拼接文件名/>


三:报表模板

<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>

通过调用external_layout来给报表添加默认的头部和尾部pdf内容会是<div class="page">里的内容

模板id需与报表声明中一致,比如上面的account.report_invoice,由于这是qweb模板,可以在docs对象中取得字段内容。

四:报表嵌入二维码

在controller中生成二维码,然后在生成报表时嵌入:

![](‘/report/barcode/QR/%s‘ % ‘My text in qr code‘)
还可以使用查询url来传多个参数:<img t-att-src="‘/report/barcode/? ???type=%s&value=%s&width=%s&height=%s‘%(‘QR‘, ‘text‘, 200, 200)"/>

五:报表格式

文件格式用report.paperformat记录来定义:

name (必选) - 用于查找及区分的名字description - 格式的描述format - 一个预定义的格式如(A0-A9,B0-B10等)或自定义,默认是A4dpi - 输出的DPI,默认90margin_top, margin_bottom, margin_left, margin_right - mm为单位的margin值page_height, page_width - mm为单位的尺寸orientation - 横向或纵向 Landscape , Portraitheader_line - boolean,是否显示标题行header_spacing - mm为单位的头部空白
<record id="paperformat_frenchcheck" model="report.paperformat"> ???<field name="name">French Bank Check</field> ???<field name="default" eval="True"/> ???<field name="format">custom</field> ???<field name="page_height">80</field> ???<field name="page_width">175</field> ???<field name="orientation">Portrait</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">80</field></record>

六:查看报表

报表是标准的web页面,所以可以通过链接直接访问:

html版本报表可以通过 : http://localhost:8069/report/html/报表名/1

pdf版本通过 : http://localhost:8069/report/pdf/报表名/1

odoo10学习笔记十三:qweb报表

原文地址:https://www.cnblogs.com/qjtjh/p/8269711.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved