From 6f5852eabf60c9fe19f0b58871d2117314b8f90c Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Thu, 28 May 2026 01:27:05 +0530 Subject: [PATCH] fix: block cancellation if reconciled with a Bank Transaction --- .../doctype/payment_entry/payment_entry.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 357df56c5e9..8bface5db11 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -292,6 +292,30 @@ class PaymentEntry(AccountsController): alert=True, ) + def before_cancel(self): + from erpnext.accounts.doctype.bank_transaction.bank_transaction import ( + get_reconciled_bank_transactions, + ) + + linked_bank_transactions = get_reconciled_bank_transactions(self.doctype, self.name) + + active_bank_transactions = [] + if linked_bank_transactions: + active_bank_transactions = frappe.get_all( + "Bank Transaction", + filters={"name": ("in", linked_bank_transactions), "docstatus": 1}, + pluck="name", + ) + if active_bank_transactions: + frappe.throw( + _( + "Payment Entry {0} is reconciled with Bank Transaction(s): {1}. Please unreconcile it before cancelling." + ).format( + frappe.bold(self.name), + ", ".join(frappe.bold(bt) for bt in active_bank_transactions), + ) + ) + def on_cancel(self): self.ignore_linked_doctypes = ( "GL Entry",