436 Views
In Odoo 14, if you want to display a header only on the first page and a footer only on the last page in a QWeb report, you can achieve this by using conditions in your QWeb template. Here’s a general approach:
Example QWeb Template
- Define the Header and Footer:
Create the header and footer sections within the QWeb template. Use conditional logic to ensure the header is displayed only on the first page and the footer only on the last page.
<template id="report_your_report_name">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<div class="page">
<!-- Header -->
<t t-if="loop.index == 0">
<div class="header">
<h1>Your Header Content</h1>
</div>
</t>
<!-- Main Content -->
<div class="content">
<h2 t-esc="doc.name" />
<!-- Add more content as needed -->
</div>
<!-- Footer -->
<t t-if="loop.index == docs|length - 1">
<div class="footer">
<h3>Your Footer Content</h3>
</div>
</t>
</div>
</t>
</t>
</template>
Explanation
<t t-foreach="docs" t-as="doc">
: Iterates through the document records.loop.index == 0
: Checks if the current loop iteration is the first one to display the header.loop.index == docs|length - 1
: Checks if the current loop iteration is the last one to display the footer.
CSS for Page Breaks
To ensure proper page breaks and layout, you might want to add some CSS:
<style>
.page {
page-break-after: always;
}
.header, .footer {
position: fixed;
width: 100%;
}
.header {
top: 0;
}
.footer {
bottom: 0;
}
</style>
Conclusion
This setup ensures that your report will show the header only on the first page and the footer only on the last page. Adjust the styling and content as needed for your specific requirements. If you encounter any issues, make sure to check the Odoo documentation or community forums for further assistance.