From d828ea6a1a986a07f82c117405940b164cbf2e7c Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Mon, 7 Oct 2024 12:33:42 +0530 Subject: [PATCH] fix: Separate `on_submit` and `before_submit` of PR (cherry picked from commit dbd7b83204d1e36790d838a5c96c55d4d93464bd) --- .../payment_request/payment_request.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 0411a311735..dc74392cba9 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -191,19 +191,28 @@ class PaymentRequest(Document): else: self.outstanding_amount = self.grand_total + def on_submit(self): if self.payment_request_type == "Outward": - self.status = "Initiated" + self.db_set("status", "Initiated") + return elif self.payment_request_type == "Inward": - self.status = "Requested" + self.db_set("status", "Requested") - if self.payment_request_type == "Inward": - if self.payment_channel == "Phone": - self.request_phone_payment() - else: - self.set_payment_request_url() - if not (self.mute_email or self.flags.mute_email): - self.send_email() - self.make_communication_entry() + send_mail = self.payment_gateway_validation() if self.payment_gateway else None + ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) + + if ( + hasattr(ref_doc, "order_type") and ref_doc.order_type == "Shopping Cart" + ) or self.flags.mute_email: + send_mail = False + + if send_mail and self.payment_channel != "Phone": + self.set_payment_request_url() + self.send_email() + self.make_communication_entry() + + elif self.payment_channel == "Phone": + self.request_phone_payment() def request_phone_payment(self): controller = _get_payment_gateway_controller(self.payment_gateway)