This question has been flagged

I have faced some of the issue page break in Qweb report in last few days. I am trying to print my Qweb report for Cheque format and single Qweb page divided into 3 different sections 

Section 1 : Displaying invoice list details
Section 2 : Bank details and amount which we will pay to our owner/tenant in MICR FONT 13B FONT
Section 3 : Displaying invoice list details

section 1 & 3 are the common and displaying the same invoices details into both of the sections and about the section2 will change as per the different amount which we will pay to owner/tenant.

Expected Result :

I have 23 invoice details are attached it into single cheque then I want to bifurcate my invoice details into different slot

sloat 1 : Display first 10 invoice details into first page
sloat 2 : Display next 10 invoice details into second page
sloat 3 : Display remaning 3 invoice details into third page

I want to bifurcate my invoice details into different sloat wise page if the total number of invoices are more than 10 lines

What I have tried from my side ?

Attempt 1 : Using counter variable and update the counter through iterating the loop and break it when 10 is reach divide by 0 Applied this code inside into loping

<t t-set="count" t-value="count+1" />
    <t t-if="count%10== 0">
         <div style="page-break-after:auto;"/> 
    </t>
</t>

Attempt 2:

<span t-esc="line_index+1"/> 
<t t-if="line_index+1%10 ==0"> 
    <div style="page-break-inside:auto !important;"> 
</t>

Avatar
Discard
Author Best Answer


I have also fixed the issue from my end after tried a lot more attempts

If any one will face the same issue in your future development so that they can also able to fix it quickly.

Create a method into specific model  : (cheque.cheque model) 

def get_invoice_details(self, invoice_ids,cheque):
    vals,container,result,val=[],[],[],1
    invoice_no=''
    for line in invoice_ids:
        desc=''
        if line.is_vendor:
            invoice_no=line.vendor_reference
        else:
            invoice_no=line.number

        pay_amt=line.payment_ids.filtered(lambda m: m.cheque_issued_id.id ==cheque.id).amount or 0.00
        for l in line.invoice_line_ids:
            desc+=str(l.product_id.default_code)+',' or ''
        vals.append({
            'date':str(line.date_invoice),
            'invoice_no':invoice_no,
            'inv_amt':str(line.amount_total),
            'description':desc,
            'pay_amt':float(pay_amt)
        })
        invoice_no=''
    for l in vals:
        if val<=len(vals):
            container.append(l)
        if val % 9 == 0:
            result.append({'section':9,'vals':container})
            container=[]
        val+=1
    if container:
        result.append({'section':4,'vals':container})
    return result

In this method I have set section key with its value into result of list for dictionary where we are using the same section to making the page break perfectly

Call the same method and iterate it into Qweb Template
<t t-foreach="o.get_invoice_details(o.invoice_ids,o)" t-as="line" >
                <div class="page">
                    <div class="col-xs-12">
                                <table style="width:100%">
                                    <thead>
                                        <tr>
                                            <th>Invoice Date</th>
                                            <th>Invoice # </th>
                                            <th>Invoice Amt</th>
                                            <th>Description  </th>
                                            <th style="text-align:right">Payment Amt</th>
                                        </tr>
                                    </thead>
                                    <t t-foreach="line.get('vals')" t-as="inv">
                                    <tbody class="sale_tbody">
                                        <tr>
                                            <td>
                                                <span t-esc="inv.get('date')" />
                                            </td>
                                            <td>                                                
                                                <span t-esc="inv.get('invoice_no')" />
                                            </td>
                                            <td>
                                                <span t-esc="o.decimal_formated_amount(float(inv.get('inv_amt',0.00)))" />
                                            </td>

                                            <td>
                                                <span t-esc="inv.get('description')" />
                                            </td>
                                            <td style="text-align:right">
                                                <span t-esc="o.decimal_formated_amount2(float(inv.get('pay_amt',0.00)))" />                                             

                                       </td>
                                        </tr>               
                                    </tbody>
                                    </t>
                                </table>
                        </div>
                      <span t-if="line.get('section') % 9 == 0" style="page-break-after: always;">
                      </span>
                </div>

As per the business logic of get_invoice_details() method which is return the data in list form and then we can user the same and render it into the XML template.

Odoo will manage the page break automatically when the condition will satisfy over the XML template system will automatically bifurcate the page according to source code.

I hope my answer may helpful for you :)






















































Avatar
Discard

Great @Dasadiya Chaitanya,

Can you please post a sample method for use with account..invoice model for invoice report?

I also need a way to correctly generate a page break after a specific number of invoice lines and I am unable to do it on Odoo 12.

Thank you very much

Best regards