From 8ba503bf0e2a6ffe9f5b3e5210c3a9dc9ec4942b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 10 Oct 2022 10:17:19 +0530 Subject: [PATCH] fix: unlink payment on invoice cancellation (cherry picked from commit 537d953f4cb2c31ca225a3487a0ce6e62b6bacb8) --- erpnext/accounts/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 9ede67848dd7..95ba3d86ceff 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -648,6 +648,16 @@ def unlink_ref_doc_from_payment_entries(ref_doc): (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", [])