From c39a44c0166f2ea2137b7fd2e790bc35e2ab0883 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Tue, 10 Oct 2023 18:20:09 +0200 Subject: [PATCH] perf: flush db at once --- .../payment_gateway_account.json | 8 ++--- .../payment_request/payment_request.json | 12 ++++---- .../payment_request/payment_request.py | 15 +++++----- .../payment_request/test_payment_request.py | 29 +++++++++++++++++-- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json index 0a74c502a8a6..cc0f3d1b52bb 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json +++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json @@ -49,7 +49,7 @@ "label": "Currency" }, { - "depends_on": "eval: doc.payment_channel !== \"Phone\"", + "depends_on": "eval: doc.payment_channel == 'Email' || (!doc.payment_channel)", "fieldname": "payment_request_message", "fieldtype": "Section Break" }, @@ -70,12 +70,12 @@ "fieldname": "payment_channel", "fieldtype": "Select", "label": "Payment Channel", - "options": "\nEmail\nPhone" + "options": "\nEmail\nPhone\nOther" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-03-27 13:10:09.836254", + "modified": "2024-03-29 18:53:09.836254", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Gateway Account", @@ -97,4 +97,4 @@ "sort_field": "creation", "sort_order": "DESC", "states": [] -} \ No newline at end of file +} diff --git a/erpnext/accounts/doctype/payment_request/payment_request.json b/erpnext/accounts/doctype/payment_request/payment_request.json index b89cca270e04..1e2879e2d269 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.json +++ b/erpnext/accounts/doctype/payment_request/payment_request.json @@ -260,7 +260,7 @@ "label": "Recipient Message And Payment Details" }, { - "depends_on": "eval: doc.payment_channel != \"Phone\"", + "depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)", "fieldname": "print_format", "fieldtype": "Select", "label": "Print Format" @@ -272,7 +272,7 @@ "label": "To" }, { - "depends_on": "eval: doc.payment_channel != \"Phone\"", + "depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)", "fieldname": "subject", "fieldtype": "Data", "in_global_search": 1, @@ -309,18 +309,18 @@ "read_only": 1 }, { - "depends_on": "eval: doc.payment_request_type == 'Inward' || doc.payment_channel != \"Phone\"", + "depends_on": "eval: doc.payment_request_type == 'Inward' || doc.payment_channel == \"Email\" || (!doc.payment_channel)", "fieldname": "section_break_10", "fieldtype": "Section Break" }, { - "depends_on": "eval: doc.payment_channel != \"Phone\"", + "depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)", "fieldname": "message", "fieldtype": "Text", "label": "Message" }, { - "depends_on": "eval: doc.payment_channel != \"Phone\"", + "depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)", "fieldname": "message_examples", "fieldtype": "HTML", "label": "Message Examples", @@ -372,7 +372,7 @@ "fieldname": "payment_channel", "fieldtype": "Select", "label": "Payment Channel", - "options": "\nEmail\nPhone", + "options": "\nEmail\nPhone\nOther", "read_only": 1 }, { diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 8c4114b44092..8d20493706ce 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -165,14 +165,13 @@ def before_submit(self): self.status = "Requested" if self.payment_request_type == "Inward": - send_mail = self.payment_gateway_validation() if self.payment_gateway else None - if send_mail and not (self.mute_email or self.flags.mute_email): - self.set_payment_request_url() - self.send_email() - self.make_communication_entry() - - elif self.payment_channel == "Phone": + 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() def request_phone_payment(self): controller = _get_payment_gateway_controller(self.payment_gateway) @@ -231,7 +230,7 @@ def payment_gateway_validation(self): return False def set_payment_request_url(self): - if self.payment_account and self.payment_channel != "Phone": + if self.payment_account and self.payment_gateway and self.payment_gateway_validation(): self.payment_url = self.get_payment_url() def get_payment_url(self): diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index ab47d80a747d..5b36387e8da8 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -19,6 +19,7 @@ payment_gateways = [ {"doctype": "Payment Gateway", "gateway": "_Test Gateway"}, {"doctype": "Payment Gateway", "gateway": "_Test Gateway Phone"}, + {"doctype": "Payment Gateway", "gateway": "_Test Gateway Other"}, ] payment_method = [ @@ -35,6 +36,13 @@ "payment_account": "_Test Bank USD - _TC", "currency": "USD", }, + { + "doctype": "Payment Gateway Account", + "payment_gateway": "_Test Gateway Other", + "payment_account": "_Test Bank USD - _TC", + "payment_channel": "Other", + "currency": "USD", + }, { "doctype": "Payment Gateway Account", "payment_gateway": "_Test Gateway Phone", @@ -111,6 +119,21 @@ def test_payment_request_linkings(self): def test_payment_channels(self): so = make_sales_order(currency="USD") + pr = make_payment_request( + dt="Sales Order", + dn=so.name, + payment_gateway_account="_Test Gateway Other - USD", + submit_doc=True, + return_doc=True, + ) + self.assertEqual(pr.payment_channel, "Other") + self.assertEqual(pr.mute_email, True) + + self.assertEqual(pr.payment_url, PAYMENT_URL) + self.assertEqual(self.send_email.call_count, 0) + self.assertEqual(self._get_payment_gateway_controller.call_count, 1) + pr.cancel() + pr = make_payment_request( dt="Sales Order", dn=so.name, @@ -124,9 +147,9 @@ def test_payment_channels(self): self.assertEqual(pr.payment_channel, "Email") self.assertEqual(pr.mute_email, False) - self.assertIsNone(pr.payment_url) + self.assertEqual(pr.payment_url, PAYMENT_URL) self.assertEqual(self.send_email.call_count, 0) # hence: no increment - self.assertEqual(self._get_payment_gateway_controller.call_count, 1) + self.assertEqual(self._get_payment_gateway_controller.call_count, 2) pr.cancel() pr = make_payment_request( @@ -180,7 +203,7 @@ def test_payment_channels(self): self.assertEqual(pr.payment_channel, "Email") self.assertEqual(pr.mute_email, True) - self.assertIsNone(pr.payment_url) + self.assertEqual(pr.payment_url, PAYMENT_URL) self.assertEqual(self.send_email.call_count, 1) # no increment on shopping cart self.assertEqual(self._get_payment_gateway_controller.call_count, 5) pr.cancel()