From 798b464ee3b9473774dd554ed5ad572a4d990e26 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Fri, 3 Sep 2021 12:30:57 +0530 Subject: [PATCH] fix: braintree payment processed twice (#27300) --- .../accounts/doctype/payment_request/payment_request.py | 8 ++++++++ erpnext/hooks.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 1570b499ac..2c967497d5 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -549,3 +549,11 @@ def make_payment_order(source_name, target_doc=None): }, target_doc, set_missing_values) return doclist + +def validate_payment(doc, method=""): + if not frappe.db.has_column(doc.reference_doctype, 'status'): + return + + status = frappe.db.get_value(doc.reference_doctype, doc.reference_docname, 'status') + if status == 'Paid': + frappe.throw(_("The Payment Request {0} is already paid, cannot process payment twice").format(doc.reference_docname)) \ No newline at end of file diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 53f40bc07c..2f7e930a2f 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -317,6 +317,9 @@ doc_events = { }, "Company": { "on_trash": "erpnext.regional.india.utils.delete_gst_settings_for_company" + }, + "Integration Request": { + "validate": "erpnext.accounts.doctype.payment_request.payment_request.validate_payment" } }