Created
August 17, 2020 13:09
-
-
Save sehrishnaz/b1f4700f77180c3d5df34809bf5a829f to your computer and use it in GitHub Desktop.
Creating custom reports using qweb in Odoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<openerp> | |
<data> | |
<!-- Add the report to the XML file responsible for reports --> | |
<report id="report_unique_xml_id" | |
model="your.model.name" | |
string="Report Name" | |
name="module_name.report_name" | |
file="module_name.report_unique_xml_id" | |
report_type="qweb-pdf" | |
/> | |
<!-- setting paper format for report --> | |
<record id="paper_format_unique_name_related_to_report" model="report.paperformat"> | |
<field name="name">Report Name</field> | |
<field name="default" eval="True" /> | |
<field name="format">A4</field> | |
<field name="page_height">0</field> | |
<field name="page_width">0</field> | |
<field name="orientation">Portrait</field> | |
<field name="margin_top">3</field> | |
<field name="margin_bottom">2</field> | |
<field name="margin_left">2</field> | |
<field name="margin_right">2</field> | |
<field name="header_line" eval="False" /> | |
<field name="header_spacing">3</field> | |
<field name="dpi">80</field> | |
</record> | |
<!-- binding paper format with qweb report--> | |
<record id="module_name.report_unique_xml_id" model="ir.actions.report.xml"> | |
<field name="paperformat_id" ref="module_name.paper_format_unique_name_related_to_report" /> | |
</record> | |
<template id="report_name"> | |
<style>.report_border { | |
border: 1px solid black; | |
} | |
.none_border { | |
border: none; | |
border-top: none; | |
} | |
.report_border > thead > tr > th, | |
.report_border > tbody > tr > th, | |
.report_border > thead > tr > td, | |
.report_border > tbody > tr > td { | |
border: 1px solid black !important; | |
}</style> | |
<!-- "docs" contains (your.model.name) which you have defined above | |
now you can access fields from docs for example data.name, data.contact_no etc | |
--> | |
<t t-foreach="docs" t-as="data"> | |
<t t-call="report.html_container"> | |
<div class="page"> | |
<div class="oe_structure" /> | |
<div class="text-center"> | |
<h3> | |
<b>Report Title Goes Here</b> | |
</h3> | |
</div> | |
<div> | |
<table class="table report_border"> | |
<!-- getting values from model in QWEB--> | |
<tr> | |
<th style="width: 25%; font-size:18px;">Name</th> | |
<td style="font-size:20px;"> | |
<span t-field="data.name" /> | |
</td> | |
</tr> | |
<!-- how to define conditional statements in QWEB --> | |
<tr> | |
<th style="width: 25%; vertical-align: top; font-size:18px;">Personal</th> | |
<td> | |
<table class="table report_border"> | |
<tr> | |
<t t-if="data.contact_number1 == False"> | |
<td style="font-size:17px;"> | |
<b>Contact No :</b> | |
<span t-field="data.contact_number2" /> | |
</td> | |
</t> | |
<t t-if="data.contact_number2 == False"> | |
<td style="font-size:17px;"> | |
<b>Contact No :</b> | |
<span t-field="data.contact_number1" /> | |
</td> | |
</t> | |
<t t-if="data.contact_number1 and data.contact_number2 != False"> | |
<td style="font-size:17px;"> | |
<b>Contact No:</b> | |
<li style="list-style-type: none;"> | |
<span t-field="data.contact_number1" /> | |
<br /> | |
</li> | |
<li style="list-style-type: none;"> | |
<span t-field="data.contact_number2" /> | |
</li> | |
</td> | |
</t> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
<!-- getting one2many relational fields in QWEb--> | |
<!-- how to use nested loops in QWEb--> | |
<tr> | |
<th style="width: 25%; vertical-align: top; font-size:18px;">Experience</th> | |
<td style="font-size:17px;"> | |
<table class="table report_border"> | |
<th style="width: 10%;">Duration</th> | |
<th style="width: 10%;">Job Title</th> | |
<th style="width: 10%;">Institution</th> | |
<tbody> | |
<t t-foreach="data" t-as="experience"> | |
<t t-foreach="experience.one2many_field" t-as="duration"> | |
<tr> | |
<td> | |
<p> | |
<t t-if="duration.curr_work == False"> | |
<span t-field="duration.date_from" t-field-options='{"format": "d-MMM-y"}' /> | |
to | |
<span t-field="duration.date_to" t-field-options='{"format": "d-MMM-y"}' /> | |
<br /> | |
</t> | |
<t t-if="duration.curr_work == True"> | |
<span t-field="duration.date_from" t-field-options='{"format": "d-MMM-y"}' /> | |
To Present | |
</t> | |
</p> | |
</td> | |
</tr> | |
</t> | |
</t> | |
</tbody> | |
</table> | |
</td> | |
</tr> | |
<!-- how to show data in ordered list in QWEB--> | |
<tr> | |
<th style="width: 25%; vertical-align: top; font-size:18px;">Ordered List</th> | |
<td style="font-size:17px;"> | |
<t t-foreach="data.one2many_field" t-as="honor"> | |
<li style="list-style-type: none;"> | |
<p t-field="honor.name" /> | |
</li> | |
</t> | |
</td> | |
</tr> | |
<!-- create table inside table row in QWEB--> | |
<tr> | |
<th style="width: 25%; vertical-align: top; font-size:18px;">Supervision</th> | |
<td style="font-size:17px;"> | |
<table class="table report_border"> | |
<th style="width: 10%;">Year</th> | |
<th style="width: 10%;">Degree</th> | |
<th style="width: 10%;">Name</th> | |
<tbody> | |
<t t-foreach="data" t-as="supervision"> | |
<t t-foreach="supervision.one2many_field" t-as="year"> | |
<tr> | |
<td> | |
<p t-esc="year.year" /> | |
</td> | |
<td> | |
<p t-esc="year.degree" /> | |
</td> | |
<td> | |
<p t-esc="year.name" /> | |
</td> | |
</tr> | |
</t> | |
</t> | |
</tbody> | |
</table> | |
</td> | |
</tr> | |
</table> | |
</div> | |
</div> | |
</t> | |
</t> | |
</template> | |
</data> | |
</openerp> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more in detail: https://learnopenerp.blogspot.com/2020/08/create-custom-report-in-odoo-using-qweb.html