odoo qweb page break table

Le interruzioni di pagina nei report qweb di Odoo possono essere un vero incubo!

Sui vari forum ci sono diverse soluzioni utilizzando le varie combinazioni di page-break-before, page-break-inside, page-break-after.

Però il funzionamento è veramente troppo discrezionale in base al tipo di contenuto, una delle esigenza più comuni è forzare il salto pagina dopo un certo numero di line, di articoli o di elementi, o renderlo condizionale in generale ad alcuni contenuti specifici della pagina.

Questo si può ottenre impostando delle variabili a livello del report con il tag t-set per esempio.

Ma nel caso di tabelle html (ovvero la maggior parte dei casi) spesso non si riesce ad avere una vera interruzione di pagina oppure si ottengono effetti indesiderati come il salto completo della prima pagina o similari.

Anche se strana, cercando a destra e a manca, ho trovato una combinazione di soluzioni che messa insieme opportunamente produce l’effetto desiderato, a scapito dell’eleganza!

Di fatto si tratta di impostare un contatore incrementale e, al verificarsi di una data condizione, forzare la chiusura e la riapertura della tabella:

<table style="width:100%;">
  <tbody>
    <t t-set="counter" t-value="0"/>
    <t t-foreach="o.loading_ids" t-as="line">
    <t t-set="counter" t-value="counter + 1"/>
      <t t-if="counter == 4">
            &lt;/tbody&gt;
            &lt;/table&gt;

            <div style="dislay: block;page-break-after: always;"/>

            &lt;table class="table"&gt;
            &lt;tbody&gt;
          <t t-set="counter" t-value="0"/>
      </t>
    <tr>
      <td><div class="headstyle">Luogo di carico</div></td>
      <td><div class="headstyle">Luogo di scarico</div></td>
    </tr>
    <tr>
      <td>
          <br/><br/><b><span t-field="line.Partenza"/></b><br/>
      </td>
      <td>
          <br/><br/><b><span t-field="line.Destinazione"/></b><br/>
      </td>
    </tr>
  </tbody>
</table>

Page breaks in Odoo’s qweb reports can be a real nightmare!

On the forums there are different solutions using various combinations of page-break-before, page-break-inside, page-break-after.

However, the operation is really too discretionary based on the type of content, one of the most common needs is to force the page jump after a certain number of lines, articles or elements, or make it conditional in general to some specific contents of the page.

This can be achieved by setting variables at the report level with the t-set tag for example.

But in the case of html tables (that is most of the cases) it is often not possible to have a real page break or you get unwanted effects such as the complete skipping of the first page or similar.

Although strange, looking left and right, I found a combination of solutions that when properly put together produces the desired effect, to the detriment of elegance!

In fact, it is a question of setting an incremental counter and, when a given condition occurs, forcing the closing and reopening of the table like in the example code before.