Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
1497 Visualizzazioni

In Odoo 16, inside a table, if the content of a row is too long and doesn't fit on the first page, the entire row moves to the next page. However, when the content is too long for the second page as well, the row gets split, with part of the content appearing on the first page and the rest on the second page. I want it to behave differently: if the content doesn't fit on the first page, it should be split at that point, rather than moving the entire row to the next page. as mentioned below.


  1. doesn't fit to the first page:

  2. when doesn't fit to the second page also:


Thanks,

Avatar
Abbandona
Risposta migliore

Hello,

The issue where table rows in Odoo PDF reports split or move to the next page is commonly related to the limitations of the PDF rendering library used in Odoo, typically wkhtmltopdf. To resolve this issue in Odoo 16 where rows in a table get split across pages, you will need to modify the way Odoo handles table row breaks when generating reports. By default, Odoo handles row content in a way that tries to keep the row together, but in cases where the content is too long, it can split the row. You can adjust the behavior by modifying the report template or the QWeb report styles.

Here's how you can address this issue:

1. Override the QWeb Template:

You will need to update the report template for your specific report, particularly if you are dealing with tables inside a report like invoices, sales orders, or custom reports.

Find the QWeb template associated with the report (usually in views/report_*).

If the issue is with a table row not splitting, add a page-break-inside: auto; CSS property to the row (<tr>) or a surrounding block element.

2. Modify the CSS for the Table Rows:

Modify the CSS to prevent the table row from staying together. You can use the page-break-inside CSS property. By default, Odoo might have this set to avoid, which means the row tries to avoid splitting and moves to the next page entirely if it doesn't fit. You will want to change this to auto so that the row can be split.

Here's an example of how to modify the page-break-inside CSS for the row:

table {

width: 100%;

border-collapse: collapse;

}

tr {

page-break-inside: auto; /* Allows row content to be split across pages */

}

td, th {

padding: 5px;

border: 1px solid #ddd;

}

This CSS will ensure that the row can be split if the content is too large to fit on the page.

3. Add a page-break-after or page-break-before for Specific Rows:

If you want to have more control over when a row is forced onto a new page (for example, for very long content), you can use page-break-after or page-break-before properties on specific rows.

Example:

.long-content-row {

page-break-after: always; /* Forces the row to start on the next page */

}

Apply this class to the specific row that needs to break and be on the next page.

4. Update the Report's style Block:

If the report's template does not have a CSS style block, you can add one to the QWeb report definition. If you're using a custom report, you can include the style block in your template:

<t t-name="your_module.report_template">

<style>

tr {

page-break-inside: auto; /* Allows row splitting */

}

.long-content-row {

page-break-after: always; /* Force next row to be on the next page */

}

</style>

<table>

<tr>

<td>Content</td>

</tr>

</table>

</t>

5. Test and Refine the Output:

After modifying the CSS and template, generate a report and test the layout. You should see that if the content is too long to fit on the first page, it will now split at the point where necessary, instead of moving the entire row to the next page. If there are any issues with content overlapping or not being split as expected, you may need to adjust the styles further.

Another approach:

1. Optimize wkhtmltopdf Settings

If you have control over wkhtmltopdf options, try enabling --disable-smart-shrinking or modifying other parameters to improve rendering.

Update the report.paperformat in Odoo to include these options:

Navigate to Settings > Technical > Reports > Paper Formats.

In the "Custom Paper Format" options, add or modify the "Custom Options" field with:

--disable-smart-shrinking

2. Consider Upgrading wkhtmltopdf

Ensure that you are using a stable and updated version of wkhtmltopdf. Some older versions have rendering issues with complex table layouts.

Recommended version: 0.12.6 or higher (as of recent stable releases).

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
mar 24
3010
1
feb 22
2321
1
lug 25
1705
1
mag 25
1698
1
apr 25
2277