Files
odoo_source/odoo/addons/base/tests/test_split_table.py
T
VAN BOSSUYT Nicolas ad06a7b2ad [IMP] base: improve PDF generation speed for large tables
This commit addresses performance issues when generating PDFs with large
tables using wkhtmltopdf. Processing time for such tables grows
exponentially with rows, causing significant delays.
Testing revealed a PDF with 250,000 rows took about an hour.

Previously, a workaround involving special XML template was provided to
users, inserting </table><table> tags every 500 rows.
This commit introduces a general solution at framework level.
Now, tables with >500 rows will automatically use this workaround,
enhancing PDF generation speed.

The number 500 is taken from opw-1689673 and seems to be a good
compromise between the number of split in tables and the processing
time by wkhtmltopdf

closes odoo/odoo#131933

Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
2023-08-21 12:39:19 +02:00

31 lines
1.5 KiB
Python

from odoo.tests.common import TransactionCase
from odoo.tools import file_open
from odoo.addons.base.models.ir_actions_report import _split_table
from lxml import etree
def cleanup_string(s):
return ''.join(s.split())
class TestSplitTable(TransactionCase):
def test_split_table(self):
# NOTE: All the tests's xml are in split_table/ relative to this file
CASES = (
("Table's len is equal to max_rows and should not be split", "simple", "simple", 3),
("Table's len is greater to max_rows and should not be split", "simple", "simple", 4),
("max_rows is 1 and every table should be split", "simple", "simple.split1", 1),
("max_row is 2 and the table should be split", "simple", "simple.split2", 2),
("Nested tables should be split", "nested", "nested.split2", 2),
("Nested tables at the start should be split", "first_nested", "first_nested.split2", 2),
("Attributes should be copied", "copy_attributes", "copy_attributes.split1", 1),
)
for description, actual, expected, max_rows in CASES:
with self.subTest(description), \
file_open(f"base/tests/split_table/{actual}.xml") as actual, \
file_open(f"base/tests/split_table/{expected}.xml") as expected:
tree = etree.fromstring(actual.read())
_split_table(tree, max_rows)
processed = etree.tostring(tree, encoding='unicode')
self.assertEqual(cleanup_string(processed), cleanup_string(expected.read()))