[FIX] account_edi: continue uploading pdf if decrypting failed

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) <wan@odoo.com>
Signed-off-by: abla001 <abla@odoo.com>
This commit is contained in:
Abdelouahab (abla)
2023-03-02 21:56:51 +01:00
parent ce3f689b2f
commit d295cdaf56
@@ -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.