odoo/odoo#203173

Created by fw-bot
Merged at bd58379c55b746f0f7dc46bdc9a1a2a747dee5a6

Statuses:

label
odoo-dev:saas-17.4-16.0-opw-4634417-fix_encrypted_original_bill_pypdf2_2_12_1-pta-424840-fw
head
d55748a288dbe3675dfe0bd2faac434c458a99b5
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