odoo/odoo#203005

Created by fw-bot
Merged at acf5f131b1e188a9d230c4bef96bf8d1bf4baecd

Statuses:

label
odoo-dev:17.0-16.0-opw-4634417-fix_encrypted_original_bill_pypdf2_2_12_1-pta-423528-fw
head
a2546f16a17a05d365b934101b99960905fa8c91
merged
3 months ago by Bugfix, Anh Thao Pham (pta)
odoo/odoo
16.0 #202129
17.0 #203005
saas-17.4 #203173
18.0 #203184
saas-18.1 #203319
saas-18.2 #203574
saas-18.3
saas-18.4
master #203596

[FW][FIX] account: fix encrypted original bill with PyPDF2 2.12.1

Steps to reproduce:
- Use version 2.12.1 of PyPDF2 as required if python version > 3.10
- Install Accounting
- Upload an encrypted PDF as a bill
- Go to the bills list view
- Select the uploaded bill
- Print "Original Bills"

Issue:
A traceback is raised:
"PyPDF2.errors.DependencyError: PyCryptodome is required for AES algorithm"

Cause:
When printing the original bill, we try to add a banner on the PDF.
If the PDF is encrypted, PyPDF2 (2.12.1) will only try to decrypt it if "PyCryptodome" library is installed.
Otherwise, it will raise a "DependencyError", which is not handled in the "except" clause.
As "PyCryptodome" library is not part of Odoo requirements, we should handle the raised "DependencyError".

Solution:
Try to import "DependencyError" from "PyPDF2.errors" and catch that exception when adding the banner to the PDF.
Our own "DependencyError" exception should be created because version 1.26.0 of PyPDF2 doesn't declare "DependencyError" and therefore the import will fail.
"NotImplementedError" is used instead in version 1.26.0 and is already handled.

opw-4634417


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

Forward-Port-Of: #202129