Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
70 Представления

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>


Аватар
Отменить
Лучший ответ

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) ​​
Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
авг. 25
2971
1
февр. 25
2622
2
июл. 25
1567
1
июл. 25
690
3
мая 25
835