pythonxmlodooodoo-13

In Odoo 13, when doing a pdf report print how to assign page break for a table such that it occurs in the beggining or end of a row


Currently, when trying to print a report where there are more table records than a single page can contain, the table will be split across multiple pages. The split occurs at whatever point reaches the bottom margin, which predictably happens in the middle of a table row and splits its contents across two pages (example shown below). Test I would like to modify this functionalitysuch that when reaching the bottom margin, a break always happens between records instead.

Following report template is used for the final print. The portion of code which indicates the main report table is encircled by xml comments

<template id="outgoing_report_template">
        <t t-call="web.html_container">
            <t t-call="web.external_layout">
                <div class="page">
                    <style>
                        .table-black-border {
                            border: 3px solid black;
                            border-collapse: collapse;
                            width: 100%;
                        }
                        .table-black-border th, .table-black-border td {
                            border: 1px solid black;
                            padding: 10px;
                            text-align: center;
                            font-size: 16px;

                        }
                    </style>

                    <img src="/custom_inventory/static/src/images/logo.png" alt="logo" width="150px" height="150px" style="float:left;margin-left:600px"/>

                    <table dir="rtl" style="text-align:center;font-size:20px;margin-left:auto;" width="30%">
                        <tr>
                            <td>
                                <span>الوزارة/الدائرة ________________________</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span><![CDATA[&nbsp;]]></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span><![CDATA[&nbsp;]]></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <pre style="border:none;">رقم          ل</pre>
                            </td>
                        </tr>
                    </table>

                    <!-- Main report content -->
                    <table dir="rtl" style="text-align:center;" width="100%">
                        <tr>
                            <th colspan="4" style="font-size:48px;">
                                <span><u>مستند الاخراجات</u></span>
                            </th>
                        </tr>
                        <tr>
                            <td>
                                <span><![CDATA[&nbsp;]]></span>
                            </td>
                        </tr>
                        <tr style="font-size:16px;">
                            <td>
                                <span>صرف الى _______________________</span>
                            </td>
                            <td>
                                <span>من قبل ________________________</span>
                            </td>
                            <td>
                                <span>للسيد ________________________</span>
                            </td>
                            <td>
                                <span>التاريخ ________________________</span>
                            </td>
                        </tr>
                        <tr>
                            <td><span><![CDATA[&nbsp;]]></span></td>
                        </tr>
                        <tr style="font-size:16px;">
                            <td><span>بموجب طلب اللوازم رقم ________________________</span></td>
                            <td><span>تاريخ ________________________</span></td>
                            <td><span>موقع من ________________________</span></td>
                            <td><span>توقيع مأمور المستودع ________________________</span></td>
                        </tr>
                    </table>

                    <br/><br/>

                    <!--main report table start-->
                    <table class="table-black-border" style="float:right;" dir="RTL" width="100%">
                        <thead>
                            <tr>
                                <th rowspan="2" width="15%"><span>رقم التسجيل</span></th>
                                <th rowspan="2"><span>نوع اللوازم و وصفها</span></th>
                                <th rowspan="2"><span>الوحدة</span></th>
                                <th rowspan="2"><span>الكمية</span></th>
                                <th colspan="2"><span>سعر الوحدة</span></th>
                                <th colspan="2"><span>سعر الاجمالي</span></th>
                                <th rowspan="2"><span>الرصيد</span></th>
                                <th rowspan="2"><span>خانة التخزين</span></th>
                                <th rowspan="2"><span>الكمية المصروفة كتابة</span></th>
                            </tr>
                            <tr>
                                <th><span>فلس</span></th>
                                <th><span>دينار</span></th>
                                <th><span>فلس</span></th>
                                <th><span>دينار</span></th>
                            </tr>
                        </thead>
                        <tr t-foreach="docs.move_ids_without_package" t-as="move_line">
                            <td><span t-field="move_line.reference"/></td>
                            <td><span t-field="move_line.product_id"/></td>
                            <td><span t-field="move_line.product_uom"/></td>
                            <td><span t-esc="('%d' %(move_line.product_uom_qty))"/></td>
                            <td>
                                <div t-if="docs.origin">
                                    <span t-esc="('%d' %(docs.get_report_price_unit(docs.origin, move_line.product_id.name) % 1 * 1000))"/>
                                </div>
                                <div t-if="not docs.origin">
                                    <span t-esc="('%d' %(move_line.product_id.product_tmpl_id.list_price % 1 * 1000))"/>
                                </div>
                            </td>
                            <td>
                                <div t-if="docs.origin">
                                    <span t-esc="('%d' %(docs.get_report_price_unit(docs.origin, move_line.product_id.name)))"/>
                                </div>
                                <div t-if="not docs.origin">
                                    <span t-esc="('%d' %(move_line.product_id.product_tmpl_id.list_price))"/>
                                </div>
                            </td>
                            <td>
                                <div t-if="docs.origin">
                                    <span t-esc="('%d' %(docs.get_report_price_subtotal(docs.origin, move_line.product_id.name) % 1 * 1000))"/>
                                </div>
                                <div t-if="not docs.origin">
                                    <span t-esc="('%d' %(move_line.product_id.product_tmpl_id.list_price * move_line.product_uom_qty % 1 * 1000))"/>
                                </div>
                            </td>
                            <td>
                                <div t-if="docs.origin">
                                    <span t-esc="('%d' %(docs.get_report_price_subtotal(docs.origin, move_line.product_id.name)))"/>
                                </div>
                                <div t-if="not docs.origin">
                                    <span t-esc="('%d' %(move_line.product_id.product_tmpl_id.list_price * move_line.product_uom_qty))"/>
                                </div>
                            </td>
                            <td><span t-field="move_line.location_id.name"/></td>
                            <td><span t-field="move_line.location_dest_id.name"/></td>
                            <td><span t-esc="docs.number2words(move_line.quantity_done)"/></td>
                        </tr>
                    </table>
                    <!--main report table end-->

                    <br/><span><![CDATA[&nbsp;]]></span><br/>

                    <table dir="rtl" style="font-size:20px;text-align:center;" width="100%">
                        <tr>
                            <td>تاريخ ________________________</td>
                            <td>الوظيفة ________________________</td>
                            <td>إسم المستلم ________________________</td>
                        </tr>
                        <tr>
                            <td><span><![CDATA[&nbsp;]]></span></td>
                        </tr>
                        <tr>
                            <td>نسخة المحاسب ________________________</td>
                            <td></td>
                            <td>توقيع المستلم ________________________</td>
                        </tr>
                        <tr>
                            <td><span><![CDATA[&nbsp;]]></span></td>
                        </tr>
                        <tr>
                            <td>قرار رقم ________________________</td>
                            <td></td>
                            <td>تاريخ ________________________</td>
                        </tr>
                    </table>
                </div>
            </t>
        </t>
    </template>
</odoo>

Solution

  • After a period of experimenting and testing, it seems that the code functions exactly as intended when the OS used is Windows. Previously the OS used was Ubuntu v20.04 which was uncooperative with regard to pdf report page breaks. However without making code changes, performing the same print actions on Windows works as intended (as shown below)

    Example picture of page break working as desired, with senstive information blurred out