diff --git a/.hgtags b/.hgtags index b6df8918dbbb7c753aa8a153684d08674704b24d_LmhndGFncw==..13065fe2a4d0c913f8f12ea15ff51bec52c94232_LmhndGFncw== 100644 --- a/.hgtags +++ b/.hgtags @@ -33,3 +33,4 @@ 07224c0905af4f9c9c1d47d4acf369ce55c5c859 17.0.1.2.0 a6c94d540cb228b9dcf7dca24e53a35158b2c9ef 17.0.1.3.0 8989efa57c7fb5f0ed7560e043cab2930184fb69 17.0.1.3.1 +c7a0de86f1d66d9e87dd7a1cc4878d799d6f50dd 17.0.1.3.2 diff --git a/NEWS.rst b/NEWS.rst index b6df8918dbbb7c753aa8a153684d08674704b24d_TkVXUy5yc3Q=..13065fe2a4d0c913f8f12ea15ff51bec52c94232_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,17 @@ 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 +---------- + +Also remove python-magic from odoo manifest requirements. + 17.0.1.3.1 ---------- diff --git a/__manifest__.py b/__manifest__.py index b6df8918dbbb7c753aa8a153684d08674704b24d_X19tYW5pZmVzdF9fLnB5..13065fe2a4d0c913f8f12ea15ff51bec52c94232_X19tYW5pZmVzdF9fLnB5 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -21,7 +21,7 @@ { "name": "Redner", "license": "AGPL-3", - "version": "17.0.1.3.1", + "version": "17.0.1.4.0", "category": "Reporting", "author": "XCG Consulting", "website": "https://orbeet.io/", @@ -43,5 +43,5 @@ ], }, "installable": True, - "external_dependencies": {"python": ["requests_unixsocket", "python-magic"]}, + "external_dependencies": {"python": ["requests_unixsocket"]}, } diff --git a/models/redner_report.py b/models/redner_report.py index b6df8918dbbb7c753aa8a153684d08674704b24d_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." )