Skip to Content
Menu
This question has been flagged
3 Replies
36368 Views

How to add page numbers as page X of Y in Qweb reports in odoo.

Avatar
Discard

Have you tried my solution below? If it helps, please upvote.

Best Answer

Try this:

<span>Page </span><span class="page" /> of <span class="topage" />

But keep in mind, this will only work when the report type is PDF, not HTML.

I am not using external_layout_footer in my Sales Order/Quote or Invoice Qweb report printouts. I instead have the header and footer written directly into the "document" Qweb views. My footer looks like this, which will give you a nice small Page Y of X in the lower left corner of the page.

<div class="footer">
            <div class="row">
                <div class="col-xs-2 pull-left">
                    <small>
                        <span>Page</span>
                        <span class="page" />
                        of
                        <span class="topage" />
                    </small>
                </div>
            </div>
        </div>

Try this out for a header:

<div class="header">
            <div class="row">
                <div class="col-xs-3">
                    <!-- <img t-if="o.company_id.logo" t-att-src="'data:image/png;base64,%s' % o.company_id.logo" style="max-height: 125px;"/> -->
                </div>
                <small>
                <div class="col-xs-2 text-right">
                    <div t-field="o.company_id.partner_id" t-field-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: true}"/>
                </div>
                <div class="col-xs-2">
                    <div t-field="o.company_id.partner_id" t-field-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;phone&quot;, &quot;website&quot;, &quot;email&quot;], &quot;no_marker&quot;: true}"/>
                </div>
                </small>
                <div class="col-xs-4">
                    <span class="text-right">
                        <h4>
                            <span t-if="o.state not in ['draft','sent']">Order N°</span>
                            <span t-if="o.state in ['draft','sent']">Quote N°</span>
                            <span t-field="o.name" />
                        </h4>
                    </span>
                    <small>
                        <div class="row">
                            <div class="col-xs-8 text-right">
                                <span t-if="o.state not in ['draft','sent']">Order Date</span>
                                <span t-if="o.state in ['draft','sent']">Quote Date</span>
                            </div>
                            <div class="col-xs-4 text-right">
                                <span t-field="o.date_order" t-field-options="{&quot;format&quot;: &quot;yyyy-MM-dd&quot;}" />
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-8 text-right">
                                <span t-if="o.write_date">Modified Date</span>
                            </div>
                            <div class="col-xs-4 text-right">
                                <span t-field="o.write_date" t-field-options="{&quot;format&quot;: &quot;yyyy-MM-dd&quot;}" />
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-8 text-right">
                                <span t-if="o.user_id.name">Salesperson</span>
                            </div>
                            <div class="col-xs-4 text-right">
                                <span t-field="o.user_id.name" />
                            </div>
                        </div>
                    </small>
                </div>
            </div>
            <div class="row">
            <small>
                <div class="col-xs-2">
                    <strong>Customer</strong>
                    <div t-field="o.partner_invoice_id" t-field-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: true}" />
                </div>
                <div class="col-xs-2">
                    <strong>Contact</strong>
                    <div t-field="o.partner_invoice_id" t-field-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;phone&quot;, &quot;mobile&quot;, &quot;email&quot;], &quot;no_marker&quot;: true}" />
                </div>
                <div class="col-xs-2">
                    <strong>Shipping Address</strong>
                    <div t-if="o.partner_shipping_id == o.partner_invoice_id">Same as billing</div>
                    <div t-if="o.partner_shipping_id != o.partner_invoice_id">
                        <div t-field="o.partner_shipping_id" t-field-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;, &quot;phone&quot;], &quot;no_marker&quot;: true}" />
                    </div>
                </div>
                <div class="col-xs-6">
                    <!-- rest of customer ref info -->
                    <strong t-if="o.state not in ['draft','sent']">Order Terms</strong>
                    <strong t-if="o.state in ['draft','sent']">Quote Terms</strong>
                    <div class="row">
                        <div class="col-xs-6">
                            <div t-if="o.client_order_ref">
                                PO / Ref:
                                <span t-field="o.client_order_ref" />
                            </div>
                            <div t-if="o.payment_term">
                                Term:
                                <span t-field="o.payment_term" />
                            </div>
                            <div t-if="o.incoterm">
                                Incoterm:
                                <span t-field="o.incoterm" />
                            </div>
                            <div t-if="o.carrier_id">
                                Delivery Method:
                                <span t-field="o.carrier_id" />
                            </div>
                        </div>
                        <div class="col-xs-6">
                            <div t-if="o.state in ['draft','sent']">
                                <div t-if="o.validity_date">
                                    Expiry Date:
                                    <span t-field="o.validity_date" t-field-options="{&quot;format&quot;: &quot;yyyy-MM-dd&quot;}" />
                                </div>
                            </div>
                            <div t-if="o.requested_date">
                                Requested Date:
                                <span t-field="o.requested_date" t-field-options="{&quot;format&quot;: &quot;yyyy-MM-dd&quot;}" />
                            </div>
                            <div t-if="o.state">
                                Status:
                                <span t-field="o.state" />
                            </div>
                        </div>
                    </div>
                
                </div>
            </small>
            </div>
</div>

Avatar
Discard

Does this work everywhere on the report? This line seemed to display the page number only when it was placed in the external_layout_footer template.

I am not using external_layout_footer in my Sales Order/Quote or Invoice Qweb report printouts. I instead have the header and footer written directly into the "document" Qweb views. My footer looks like this:

Post it as an answer... that part supports markup

Author

@Cliff Kujala Is it possible to add the header in all pages of the report?

@ Gopakumar N G Yes this is possible. I will edit my answer above so you can see the code to add a header inside the "document" Qweb view.

Are you viewing as PDF or HTML? It will only work as PDF. You also need to make sure you are calling out the class of the span tag correctly. See html/xml as written above. Anything that doesn't pass strict XML won't work.

Author

@Cliff Kujala For getting the header in all pages of the report, the div with class="header"is to be added in which part of the report? Could you please provide your report file or post it in the answer?

Best Answer

Try this in xml.view:

<template id="external_layout_footer">
    <div class="footer">
        <div class="text-center" style="border-top: 1px solid black;">        

            <ul class="list-inline">
                <li>Page:</li>
                <li><span class="page"/></li>
                <li>/</li>
                <li><span class="topage"/></li>
            </ul>
        </div>
    </div>     

</template>

Avatar
Discard

Thanks @vasanth this code very helpfull for me

How i can img to footer, i have my own module but i can add images with the images do not show up.

Best Answer

tell me without using external and internal layout'

Avatar
Discard