odoo/odoo#203184

Created by fw-bot
Merged at 9dbf74da839b55ef6afb38510b8002fe3a6be87d

Statuses:

label
odoo-dev:18.0-16.0-opw-4634417-fix_encrypted_original_bill_pypdf2_2_12_1-pta-425103-fw
head
17e29c09e46f057e19cd39f6b0452c2639b40547
merged
2 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
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: #203005
Forward-Port-Of: #202129