odoo/odoo#203574

Created by fw-bot
Merged at 1ccbd2b79f5df2646aebf9ff2a98045cf06c0086

Statuses:

label
odoo-dev:saas-18.2-16.0-opw-4634417-fix_encrypted_original_bill_pypdf2_2_12_1-pta-425351-fw
head
e29a9acce39934713dbf82981539d6168e53504d
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: #203319
Forward-Port-Of: #202129