From 19c318df68c187ed6727c160fcf50133a560cdd2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 1 Jul 2026 08:24:28 +0000 Subject: [PATCH] fix(banking): handle blank password protected PDFs and negative amounts in CR/DR columns (backport #56690) (#56694) fix(banking): handle blank password protected PDFs and negative amounts in CR/DR columns (#56690) * fix(banking): strip signs from amount if column has CR/DR values * fix(banking): try decrypting PDF with a blank password (cherry picked from commit 300471da12513f398965c93e618de2be79450679) Co-authored-by: Nikhil Kothari --- .../bank_statement_import_log.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/bank_statement_import_log/bank_statement_import_log.py b/erpnext/accounts/doctype/bank_statement_import_log/bank_statement_import_log.py index f50549befa1..c4ac1deef69 100644 --- a/erpnext/accounts/doctype/bank_statement_import_log/bank_statement_import_log.py +++ b/erpnext/accounts/doctype/bank_statement_import_log/bank_statement_import_log.py @@ -829,7 +829,9 @@ def compute_final_transactions(transaction_rows: list, date_format: str, amount_ if amount_format == 'Amount column has "CR"/"DR" values': amount = transaction_row.get("amount") - float_amount = get_float_amount(amount) + + # If the amount column has CR/DR in it - we should remove any signs (negative or positive) from the amount + float_amount = abs(get_float_amount(amount) or 0) if "cr" in amount.lower(): return 0, float_amount else: @@ -932,14 +934,18 @@ def extract_pdf_tables(content: bytes, password: str | None = None) -> list[dict from pypdf import PdfReader reader = PdfReader(io.BytesIO(content)) - if reader.is_encrypted and (not password or not reader.decrypt(password)): - frappe.throw( - _( - "This PDF is password protected. Please set the correct statement password on the" - " Bank Account and try again." - ), - title=_("Password Required"), - ) + if reader.is_encrypted: + # Try opening the PDF with a password - if no password is provided, try with a blank password + if not password: + password = "" + if not reader.decrypt(password): + frappe.throw( + _( + "This PDF is password protected. Please set the correct statement password on the" + " Bank Account and try again." + ), + title=_("Password Required"), + ) text_settings = {"vertical_strategy": "text", "horizontal_strategy": "text"} tables = []