odoo/odoo#203173
Created by fw-bot
Statuses:
- legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/template: Contact runbot team on discord for help.
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
- 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.
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr