From 4c120710ede233f046e723a8d057f3102e68acf6 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Mon, 29 Jan 2024 15:06:15 +0100 Subject: [PATCH 1/2] fix: Auto update default mode of payment from payment request --- .../payment_request/payment_request.py | 40 ++++++++++++++++++- .../payment_request/payment_request_list.js | 7 +++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index f0e1bc066a8..8a5a59b745a 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -149,6 +149,10 @@ class PaymentRequest(Document): ) def on_submit(self): + if self.payment_request_type == "Outward": + self.db_set("status", "Initiated") + return + if self.payment_request_type == "Inward": self.db_set("status", "Requested") send_mail = True @@ -170,8 +174,30 @@ class PaymentRequest(Document): self.send_email(communication) self.update_subscription_mode_of_payment() - else: - self.db_set("status", "Initiated") + + advance_payment_doctypes = frappe.get_hooks( + "advance_payment_receivable_doctypes" + ) + frappe.get_hooks("advance_payment_payable_doctypes") + if self.reference_doctype in advance_payment_doctypes: + # set advance payment status + ref_doc.set_total_advance_paid() + + def request_phone_payment(self): + controller = _get_payment_gateway_controller(self.payment_gateway) + request_amount = self.get_request_amount() + + payment_record = dict( + reference_doctype="Payment Request", + reference_docname=self.name, + payment_reference=self.reference_name, + request_amount=request_amount, + sender=self.email_to, + currency=self.currency, + payment_gateway=self.payment_gateway, + ) + + controller.validate_transaction_currency(self.currency) + controller.request_for_payment(**payment_record) def on_cancel(self): self.check_if_payment_entry_exists() @@ -260,6 +286,11 @@ class PaymentRequest(Document): if frappe.db.has_column(self.reference_doctype, "supplier"): return frappe.db.get_value(self.reference_doctype, self.reference_name, "supplier") + def register_default_payment_method(self): + for dt in ["Customer", "Supplier", "Subscription"]: + if self.get(dt.lower()): + frappe.db.set_value(dt, self.get(dt.lower()), "mode_of_payment", self.mode_of_payment) + @property def reference_document(self): return frappe.get_doc(self.reference_doctype, self.reference_name) @@ -552,10 +583,15 @@ class PaymentRequest(Document): elif (curr_status == "Requested") and (next_status == "Pending") and is_not_draft: self.db_set("status", "Pending", commit=True) elif (curr_status in ("Pending", "Requested")) and (next_status == "Payment Method Registered"): + if curr_status == "Requested": + self.db_set("status", "Pending", commit=True) self.run_method("set_payment_method_registered") self.db_set("transaction_reference", reference_no, commit=True) + if curr_status in ("Pending", "Paid"): + self.register_default_payment_method() + return self.get_redirection() def set_payment_method_registered(self): diff --git a/erpnext/accounts/doctype/payment_request/payment_request_list.js b/erpnext/accounts/doctype/payment_request/payment_request_list.js index 6c400fbfa7d..7a0a838d496 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request_list.js +++ b/erpnext/accounts/doctype/payment_request/payment_request_list.js @@ -5,7 +5,10 @@ frappe.listview_settings['Payment Request'] = { return [__("Draft"), "darkgrey", "status,=,Draft"]; } else if(doc.status == "Initiated") { - return [__("Initiated"), "orange", "status,=,Initiated"]; + return [__("Initiated"), "blue", "status,=,Initiated"]; + } + else if(doc.status == "Requested") { + return [__("Requested"), "blue", "status,=,Requested"]; } else if(doc.status == "Paid") { return [__("Paid"), "green", "status,=,Paid"]; @@ -20,7 +23,7 @@ frappe.listview_settings['Payment Request'] = { return [__("Failed"), "red", "status,=,Failed"]; } else if(doc.status == "Completed") { - return [__("Completed"), "blue", "status,=,Completed"]; + return [__("Completed"), "green", "status,=,Completed"]; } } } -- GitLab From 5aadb266a6c68f4925e22336e67d3855eb182f29 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Mon, 29 Jan 2024 17:20:14 +0000 Subject: [PATCH 2/2] fix: remove develop specific code --- .../accounts/doctype/payment_request/payment_request.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 8a5a59b745a..badeea0ca1e 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -175,13 +175,6 @@ class PaymentRequest(Document): self.update_subscription_mode_of_payment() - advance_payment_doctypes = frappe.get_hooks( - "advance_payment_receivable_doctypes" - ) + frappe.get_hooks("advance_payment_payable_doctypes") - if self.reference_doctype in advance_payment_doctypes: - # set advance payment status - ref_doc.set_total_advance_paid() - def request_phone_payment(self): controller = _get_payment_gateway_controller(self.payment_gateway) request_amount = self.get_request_amount() -- GitLab