diff --git a/NEWS.rst b/NEWS.rst index 921a4e6a3c109d483eabe06197e26d954821c1f8_TkVXUy5yc3Q=..13065fe2a4d0c913f8f12ea15ff51bec52c94232_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,12 @@ Changelog ========= +17.0.1.4.0 +---------- + +Remove pypdf compatibility code to use Odoo pypdf compatibility instead. +Requires a Odoo with `[ADD] *: pypdf 3.x compatibility <https://github.com/odoo/odoo/commit/fddf53c9b6bcaea1a9ff7e041c0ccbb65a4647c8>`_. + 17.0.1.3.2 ---------- diff --git a/__manifest__.py b/__manifest__.py index 921a4e6a3c109d483eabe06197e26d954821c1f8_X19tYW5pZmVzdF9fLnB5..13065fe2a4d0c913f8f12ea15ff51bec52c94232_X19tYW5pZmVzdF9fLnB5 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -21,7 +21,7 @@ { "name": "Redner", "license": "AGPL-3", - "version": "17.0.1.3.2", + "version": "17.0.1.4.0", "category": "Reporting", "author": "XCG Consulting", "website": "https://orbeet.io/", diff --git a/models/redner_report.py b/models/redner_report.py index 921a4e6a3c109d483eabe06197e26d954821c1f8_bW9kZWxzL3JlZG5lcl9yZXBvcnQucHk=..13065fe2a4d0c913f8f12ea15ff51bec52c94232_bW9kZWxzL3JlZG5lcl9yZXBvcnQucHk= 100644 --- a/models/redner_report.py +++ b/models/redner_report.py @@ -1,7 +1,7 @@ ############################################################################## # # Redner Odoo module -# Copyright © 2016, 2024 XCG Consulting <https://xcg-consulting.fr> +# Copyright © 2016, 2024, 2025 XCG Consulting <https://xcg-consulting.fr> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -30,9 +30,10 @@ from odoo import _, api, fields, models # type: ignore[import-untyped] from odoo.exceptions import ValidationError # type: ignore[import-untyped] +from odoo.tools.pdf import PdfFileReader, PdfFileWriter # type: ignore[import-untyped] from ..utils import formats # type: ignore[import-untyped] from ..utils.formats import Formats # type: ignore[import-untyped] logger = logging.getLogger(__name__) @@ -33,17 +34,9 @@ from ..utils import formats # type: ignore[import-untyped] from ..utils.formats import Formats # type: ignore[import-untyped] logger = logging.getLogger(__name__) -_pypdf2 = False -try: - from pypdf import PdfWriter -except ImportError: - from PyPDF2 import PdfFileReader, PdfFileWriter - - _pypdf2 = True - class RednerReport(models.TransientModel): _name = "redner.report" @@ -134,8 +127,8 @@ return result_path @api.model - def _merge_pdf(self, reports_path): + def _merge_pdf(self, reports_path: list[str]): """Merge PDF files into one. :param reports_path: list of path of pdf files :returns: path of the merged pdf """ @@ -138,6 +131,8 @@ """Merge PDF files into one. :param reports_path: list of path of pdf files :returns: path of the merged pdf """ - writer = PdfFileWriter() if _pypdf2 else PdfWriter() + # unlike odoo.tool.pdf.merge_pdf, does not store both files to merge and + # merged files in memory; only the merged file and a single file. + writer = PdfFileWriter() for path in reports_path: @@ -143,4 +138,4 @@ for path in reports_path: - if _pypdf2: - reader = PdfFileReader(path) + with open(path) as fd: + reader = PdfFileReader(fd, strict=False) writer.appendPagesFromReader(reader) @@ -146,6 +141,4 @@ writer.appendPagesFromReader(reader) - else: - writer.append(path) merged_file_fd, merged_file_path = tempfile.mkstemp( suffix=".pdf", prefix="report.merged.tmp." )