fix: unlink payment on invoice cancellation
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index c5eb7d8..5b4b712 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -648,6 +648,16 @@
(now(), frappe.session.user, ref_doc.doctype, ref_doc.name),
)
+ ple = qb.DocType("Payment Ledger Entry")
+
+ qb.update(ple).set(ple.against_voucher_type, ple.voucher_type).set(
+ ple.against_voucher_no, ple.voucher_no
+ ).set(ple.modified, now()).set(ple.modified_by, frappe.session.user).where(
+ (ple.against_voucher_type == ref_doc.doctype)
+ & (ple.against_voucher_no == ref_doc.name)
+ & (ple.delinked == 0)
+ ).run()
+
if ref_doc.doctype in ("Sales Invoice", "Purchase Invoice"):
ref_doc.set("advances", [])