From 85750746f6789c7f28d363705b2bd2ca1a10504d Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 30 Dec 2020 15:43:02 +0000 Subject: [PATCH] [FIX] base: Original bills on encrypted pdf Steps to reproduce the bug: -Let's consider two vendor bills VB1 and VB2 -VB1 and VB2 have both a PDF in attachment P1 and P2 respectively (the original bills from the suppliers) -Let's consider that P2 is encrypted - In the list view of vendor bills, select VB1 and VB2 and print original bills Bug: An error was raised because it is not possible to merge P2 with P1 as P2 is encrypted. opw:2389679 closes odoo/odoo#63999 X-original-commit: 0918b29ce765a159ba2b128bca9170f1230fdb78 Signed-off-by: Laurent Smet Signed-off-by: Simon Goffin (sig) --- odoo/addons/base/i18n/base.pot | 6 ++++++ odoo/addons/base/models/ir_actions_report.py | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index 1d98a6304a1..612dae8470e 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -18694,6 +18694,12 @@ msgid "" "again after refreshing." msgstr "" +#. module: base +#: code:addons/base/models/ir_actions_report.py:0 +#, python-format +msgid "One of the documents, you try to merge is encrypted" +msgstr "" + #. module: base #: code:addons/models.py:0 #, python-format diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index ecbdda19b17..db3b875fad3 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -23,7 +23,7 @@ from lxml import etree from contextlib import closing from distutils.version import LooseVersion from reportlab.graphics.barcode import createBarcodeDrawing -from PyPDF2 import PdfFileWriter, PdfFileReader +from PyPDF2 import PdfFileWriter, PdfFileReader, utils from collections import OrderedDict from collections.abc import Iterable from PIL import Image, ImageFile @@ -678,7 +678,10 @@ class IrActionsReport(models.Model): if len(streams) == 1: result = streams[0].getvalue() else: - result = self._merge_pdfs(streams) + try: + result = self._merge_pdfs(streams) + except utils.PdfReadError: + raise UserError(_("One of the documents, you try to merge is encrypted")) # We have to close the streams after PdfFileWriter's call to write() close_streams(streams)