How I can create a custom header and footer for my Custom Qweb Report?
I have tried with the explained here, but it doesn't work, maybe it's due to the previous Odoo version.
Is there a way to make this work on Odoo 10?
You can modify the original footer and header views directly:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="external_layout_header" inherit_id="report.external_layout_header">
<!-- make here your template modifications as usual -->
</template>
<template id="external_layout_footer" inherit_id="account.external_layout_footer">
<!-- make here your template modifications as usual -->
</template>
</odoo>
The original footer template is this one:
<template id="external_layout_footer">
<div class="footer">
<div class="text-center" style="border-top: 1px solid black;">
<ul t-if="not company.custom_footer" class="list-inline">
<t t-set="company" t-value="company.sudo()"/>
<li t-if="company.phone">Phone: <span t-field="company.phone"/></li>
<li t-if="company.fax and company.phone">&bull;</li>
<li t-if="company.fax">Fax: <span t-field="company.fax"/></li>
<li t-if="company.email and company.fax or company.email and company.phone">&bull;</li>
<li t-if="company.email">Email: <span t-field="company.email"/></li>
<li t-if="company.website and company.email or company.website and company.fax or company.website and company.phone">&bull;</li>
<li t-if="company.website">Website: <span t-field="company.website"/></li>
</ul>
<ul t-if="not company.custom_footer" class="list-inline" name="financial_infos">
<li t-if="company.vat">TIN: <span t-field="company.vat"/></li>
</ul>
<t t-if="company.custom_footer">
<span t-raw="company.rml_footer"/>
</t>
<ul class="list-inline">
<li>Page:</li>
<li><span class="page"/></li>
<li>/</li>
<li><span class="topage"/></li>
</ul>
</div>
</div>
</template>
And the original header template is this one:
<template id="external_layout_header">
<div class="header">
<div class="row">
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
<div class="row zero_min_height">
<div class="col-xs-12">
<div style="border-bottom: 1px solid black;"></div>
</div>
</div>
<div class="row">
<div class="col-xs-6" name="company_address">
<span t-field="company.partner_id"
t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'
style="border-bottom: 1px solid black; display:inline-block;"/>
</div>
</div>
</div>
</template>
You can make different footers and headers for different models
<t t-if="'model_name' in o and o.model_name == 'account_invoice'">
<!-- your custom footer or hedaer for invoices -->
</t>
But if you want to use another totally different from these, you will need to create an alternative to the the external layout template:
<!-- ORIGINAL -->
<template id="external_layout">
<!-- Multicompany -->
<t t-if="not o and doc">
<t t-set="o" t-value="doc"/>
</t>
<t t-if="o and 'company_id' in o">
<t t-set="company" t-value="o.company_id"></t>
</t>
<t t-if="not o or not 'company_id' in o">
<t t-set="company" t-value="res_company"></t>
</t>
<t t-call="report.external_layout_header" />
<t t-raw="0" />
<t t-call="report.external_layout_footer" />
</template>
<!-- CUSTOM -->
<template id="custom_external_layout">
<!-- Multicompany -->
<t t-if="not o and doc">
<t t-set="o" t-value="doc"/>
</t>
<t t-if="o and 'company_id' in o">
<t t-set="company" t-value="o.company_id"></t>
</t>
<t t-if="not o or not 'company_id' in o">
<t t-set="company" t-value="res_company"></t>
</t>
<t t-call="my_module.custom_external_layout_header" />
<t t-raw="0" />
<t t-call="my_module.custom_external_layout_footer" />
</template>
And use it in your report template:
<template id="your_report_document">
<t t-call="my_module.custom_external_layout">
<div class="page">
<!-- your report content -->
</div>
</t>
</template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With