Skip to Content
Menu
This question has been flagged
2 Replies
126 Zobrazenia

I am customizing a QWeb PDF report in Odoo17 (Delivery Slip).

My problem: the footer does not stay at the bottom of the page.

  • If I use margin-top, it works but it is hard-coded and breaks when content is long/short.
  • If I use position:absolute; bottom:0, with relative to the page, the footer sticks to the bottom of only the first page.
  • I tried using position : fixed, bottom:0, the footer disappears
  • I also tried using odoo built in class footer and the footer disappears

Note: The content is dynamically rendered by the one2many tree inside delivery order


Here's my simplified code:
<div class="page">

    <div class="container">

        <!-- report content / table -->

    </div>


    <div class="custom-footer">

        <p>Notes: ...</p>

        <p>Signature: ...</p>

    </footer>

</div>


Avatar
Zrušiť
Best Answer

Hi,


To print the header/footer only on the first/last page, you can use the OCA module.

* https://odoo-community.org/shop/report-qweb-element-page-visibility-2192

After installing the module, use the first-page or last-page class.

Header


<div class="header">

    <div class="first-page">

        <div class="row">

            <img t-if="company.custom_report_header"

                 t-att-src="image_data_uri(company.custom_report_header)"

                 alt="Logo" width="100%"/>

        </div>

    </div>

</div>



Footer.


<div class="footer o_standard_footer">

    <div class="last-page">

        <div style="width: 100%;">

             <img t-if="company.custom_report_footer"

             t-att-src="image_data_uri(company.custom_report_footer)"

             alt="Logo" width="100%"/>

          </div>


      </div

</div>



Hope it helps

Avatar
Zrušiť
Best Answer

Hi Jason

I was struggling with this issue too for a long time, and have not found a really clean solution. Currently I am using the following workaround:

- Create a helper report with exactly the same content (just duplicate the existing one)
- Write a method on the report model, which renders the helper report, and then analyzes the pdf and returns the page count
- Use the method in the final report, it will output the page count of the report, with this you can then dynamically set the position absolute top of the footer. 

Below are the code examples. 

Relevant Parts of the XML in the final report (only copied the relevant lines here)

<t t-set="page_count_page_2" t-value="o.get_report_page_count('custom_module.pdf_quote_report_helper_template')"/>
<t t-set="footer_top" t-value="1048.3 if page_count_page_2 == 2 else 670.6"/>
<!-- Footer is positioned dynamically according to page content using footer_top -->
<div t-att-style="'position: absolute; left: 0mm; width: 292mm; height: 85mm; background: #122439; top: %.1fmm;' % footer_top">



Render Report Page Count: 

def get_report_page_count(self, report_name):
"""
This method is used to render a helper report inside the sale quotation report and returns
its page count. This is needed for the dynamic positioning of page 2 footer, because the
footer should only be shown at the bottom of the last page of the budget and payment details
"""
self.ensure_one()
report_action = self.env.ref(report_name)
pdf_content, content_type = self.env['ir.actions.report']._render_qweb_pdf(report_action.id, [self.id])
pdf_stream = io.BytesIO(pdf_content)
pdf_reader = PdfReader(pdf_stream)
return len(pdf_reader.pages) ​​
Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
2
aug 25
2973
1
feb 25
2637
2
júl 25
1571
1
júl 25
692
3
máj 25
835