简体   繁体   中英

Qweb custom header in odoo

I have now qweb report in PDF. But if my reports (sale order, for example) have more than one page, the header is on EACH page.

Only one field is displayed on the first page header. Other fields are repeated on each page header. How to put one field header only on the first page? /h3 tag/

Thanks Here is my code:

<template id="payment_header">
        <div class="header">
            <div style="border: 1px solid black;">
                <div class="col-xs-3" style="border: 1px solid black;">
                    <table>
                        <tr class="text-left">
                            <ul class="list-inline">
                                <li>
                                    <span class="page"/>
                                </li>
                                <li>/</li>
                                <li>
                                    <span class="topage"/>
                                </li>
                            </ul>
                        </tr>
                        <tr>
                            <span>SHOP:</span>
                            <span t-esc="warehouse"/>
                        </tr>
                    </table>

                </div>
                <div>
                    <div class="center">
                        **<h3 class="text-center">
                            <font color="white">Payment</font>
                        </h3>**
                    </div>
                </div>
                <div class="col-xs-4 pull-right" style="margin-top:20px; font-size: 12px; border: 1px solid black;">
                    <span>Period</span>
                    <span t-esc="date_to" t-field-options="{'format': 'yyyy/MM/dd'}"/> ~
                    <span t-esc="date_from" t-field-options="{'format': 'yyyy/MM/dd'}"/>
                </div>
            </div>
        </div>
    </template>

I found this free Odoo addon. It might help you.

https://apps.openerp.com/apps/modules/10.0/report_qweb_element_page_visibility/

In this Example addon, you can add some Javascript code to report XML.

Here is the code example

layouts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <template id="minimal_layout" inherit_id="report.minimal_layout">
        <xpath expr="//t[@t-if='subst is True']" position="replace">
            <t t-if="subst is True">
                <script>
                    function subst() {
                        var vars = {};
                        var x = document.location.search.substring(1).split('&amp;');
                        for (var i in x) {
                            var z = x[i].split('=', 2);
                            vars[z[0]] = unescape(z[1]);
                        }
                        var x=['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection'];
                        for (var i in x) {
                            var y = document.getElementsByClassName(x[i]);
                            for (var j=0; j&lt;y.length; ++j)
                                y[j].textContent = vars[x[i]];
                        }
                        var operations = {
                            'not-first-page': function (elt) {
                                elt.style.visibility = (vars.page === vars.frompage) ? "hidden" : "visible";
                            },
                            'not-last-page': function (elt) {
                                elt.style.visibility = (vars.page === vars.topage) ? "hidden" : "visible";
                            },
                            'first-page': function (elt) {
                                elt.style.visibility = (vars.page === vars.frompage) ? "visible" : "hidden";
                            },
                            'last-page': function (elt) {
                                elt.style.visibility = (vars.page === vars.topage) ? "visible" : "hidden";
                            },
                        };
                        for (var klass in operations) {
                            var y = document.getElementsByClassName(klass);
                            for (var j=0; j&lt;y.length; ++j)
                                operations[klass](y[j]);
                        }
                    }
                </script>
            </t>
        </xpath>
    </template>
</odoo>

And then add below code to __manifest__.py:

'data': [
    'views/layouts.xml',
],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM