From a75a69a01e4781215b23514fd2a4aedd45d729bc Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Thu, 22 Feb 2024 16:00:52 +0530 Subject: [PATCH] fix: only check for delinked PLEs (cherry picked from commit 146c5b3e16b0521f0590aa6dfa957979fc6f3d9a) --- erpnext/controllers/accounts_controller.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e3c59d4dab30..89f13bbb4b4e 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -346,7 +346,12 @@ def on_trash(self): ple = frappe.qb.DocType("Payment Ledger Entry") frappe.qb.from_(ple).delete().where( (ple.voucher_type == self.doctype) & (ple.voucher_no == self.name) - | ((ple.against_voucher_type == self.doctype) & (ple.against_voucher_no == self.name)) + | ( + (ple.against_voucher_type == self.doctype) + & (ple.against_voucher_no == self.name) + & ple.delinked + == 1 + ) ).run() frappe.db.sql( "delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s", (self.doctype, self.name)