This question has been flagged
1 Reply
25550 Views

Hello everyone.

I have the need to add a page-break on core Odoo invoice report report after a specific number of lines. Let's say 10 lines.

I have found several samples and information about which tags to use and how to use "if statements" for adding the page break, but unfortunately any of this samples help me because I do not know where to add the page-break tag.

I have found that the most used tags are:

<p style="page-break-before:always;"> </p> (most reports use this type)
<p style="page-break-after:always"></p>
<div style="page-break-after: auto;"><span style="display: none;"></span>
</div> <p style="page-break-inside: avoid"></p>
<div style="page-break-inside: auto"></div>

Also found that one can use "if statements" inside the "for each" loops with the help of counter variables. For instance:

<t t-foreach="o.line_ids" t-as="line">
    <t t-if="line_index == 13">
        <div style="page-break-after: always;"><br/></div>
    </t>
</t>

Ok. Everything seems to be very easy, but all tests I have made were unsuccessful.

The core Odoo invoice report already have the "<t t-foreach...":

The core report (part of it):

<t t-foreach="o.invoice_line_ids" t-as="line">
    <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
    <t t-set="current_subtotal" t-value="current_subtotal + line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
    <tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
    <t t-if="not line.display_type" name="account_invoice_line_accountable">
        <td name="account_invoice_line_name"><span t-field="line.name"/></td>
        <td class="d-none"><span t-field="line.origin"/></td>
        <td class="text-right">
            <span t-field="line.quantity"/>
            <span t-field="line.uom_id" groups="uom.group_uom"/>
        </td>
        <td t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
            <span t-field="line.price_unit"/>
        </td>
        ...more code here
</t> #End of for loop here

On my understanding, Qweb starts the loop and for every line (record) it finds, it will add the <tr's> and <td's> based on table structure.

So, based on that, I have tried to use qweb variables and an if statement to increase a counter, and if the 10th value is reached, qweb adds a page break.

So I have tried:


<t t-set="counter" t-value="0" />

<t t-foreach="o.invoice_line_ids" t-as="line">

    <t t-if="counter == 10">
        <p style="page-break-before:always;"> </p>
    </t>
    <t t-set="counter" t-value="counter + 1" />
    
....here starts the core Odoo report data
    <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
    <t t-set="current_subtotal" t-value="current_subtotal + line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
    <tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
    <t t-if="not line.display_type" name="account_invoice_line_accountable">
        <td name="account_invoice_line_name"><span t-field="line.name"/></td>
        <td class="d-none"><span t-field="line.origin"/></td>
        <td class="text-right">
            <span t-field="line.quantity"/>
            <span t-field="line.uom_id" groups="uom.group_uom"/>
        </td>
        <td t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
            <span t-field="line.price_unit"/>
        </td>
        ...more code here
</t> #End of for loop here

Using this approach it does not work and it adds a page break at the first page and the full report content (table header, rows and columns) goes to the second page.

Also tried to add the full code starting from the "foreach" inside the if condition and using this approach, I can only see the table header and cannot see the rows and columns...

Can anyone please send me a sample on where should I put this if condition in order to get the desired result? Break the page after the 10th invoice line?

Thank you all very much in advance

Best regards

PM


Avatar
Discard

I have same problem.How did you solve this?

Any luck in finding a solution for this?

Best Answer

Hello,

You must reinitialize your counter I think like this or use modulo if possible in qweb.

 

<t t-if="counter == 10">
<p style="page-break-before:always;"> </p>

<t t-set="counter" t-value="0"/>
</t>

<t t-set="counter" t-value="counter + 1" />

Regards,

Avatar
Discard