# HG changeset patch # User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr> # Date 1738156953 -3600 # Wed Jan 29 14:22:33 2025 +0100 # Branch 17.0 # Node ID 13065fe2a4d0c913f8f12ea15ff51bec52c94232 # Parent 921a4e6a3c109d483eabe06197e26d954821c1f8 ✨ 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) diff --git a/NEWS.rst b/NEWS.rst --- 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 --- 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 --- 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,20 +30,13 @@ 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__) -_pypdf2 = False -try: - from pypdf import PdfWriter -except ImportError: - from PyPDF2 import PdfFileReader, PdfFileWriter - - _pypdf2 = True - class RednerReport(models.TransientModel): _name = "redner.report" @@ -134,18 +127,18 @@ 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 """ - 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: - if _pypdf2: - reader = PdfFileReader(path) + with open(path) as fd: + reader = PdfFileReader(fd, strict=False) writer.appendPagesFromReader(reader) - else: - writer.append(path) merged_file_fd, merged_file_path = tempfile.mkstemp( suffix=".pdf", prefix="report.merged.tmp." )