From d295cdaf565af322e535b86002c3c291d7ec51fd Mon Sep 17 00:00:00 2001 From: "Abdelouahab (abla)" Date: Mon, 27 Feb 2023 15:14:25 +0000 Subject: [PATCH] [FIX] account_edi: continue uploading pdf if decrypting failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To reproduce ============ - on accounting -> Vendor -> Bills - upload the PDF attached on the ticket an exception is raised Problem ======= PyPDF2 finds that this pdf is encrypted,so we try to decrypt it with empty password, but the decryption fails which rise an error. Solution ======== according to this [commit](https://github.com/odoo/odoo/commit/851fe64f7789bb398383c22e3ebbaebb051791f6), when the decryption fails we skip reading the attachments and carry on to allow the user to upload the document. opw-3196780 closes odoo/odoo#114269 X-original-commit: 124250d123666ea818d2c8004cadae2ccc43aa0e Signed-off-by: William André (wan) Signed-off-by: abla001 --- addons/account_edi/models/account_edi_format.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/account_edi/models/account_edi_format.py b/addons/account_edi/models/account_edi_format.py index 0bb5e791a97..d945f79ad2c 100644 --- a/addons/account_edi/models/account_edi_format.py +++ b/addons/account_edi/models/account_edi_format.py @@ -8,6 +8,7 @@ from odoo.tools import html_escape from odoo.exceptions import RedirectWarning from lxml import etree +from struct import error as StructError import base64 import io import logging @@ -242,7 +243,7 @@ class AccountEdiFormat(models.Model): try: for xml_name, content in pdf_reader.getAttachments(): to_process.extend(self._decode_xml(xml_name, content)) - except NotImplementedError as e: + except (NotImplementedError, StructError) as e: _logger.warning("Unable to access the attachments of %s. Tried to decrypt it, but %s." % (filename, e)) # Process the pdf itself.