Skip to content

Commit

Permalink
chore: devoid pr of hard to maintain code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Apr 2, 2024
1 parent 4214884 commit 7b03243
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
36 changes: 13 additions & 23 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,7 @@ def on_submit(self):

if self.payment_request_type == "Inward":
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":
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()
Expand Down Expand Up @@ -220,14 +213,12 @@ def on_cancel(self):
self.set_as_cancelled()

def make_invoice(self):
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
if hasattr(ref_doc, "order_type") and ref_doc.order_type == "Shopping Cart":
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice

si = make_sales_invoice(self.reference_name, ignore_permissions=True)
si.allocate_advances_automatically = True
si = si.insert(ignore_permissions=True)
si.submit()
si = make_sales_invoice(self.reference_name, ignore_permissions=True)
si.allocate_advances_automatically = True
si = si.insert(ignore_permissions=True)
si.submit()

def payment_gateway_validation(self):
try:
Expand Down Expand Up @@ -283,7 +274,8 @@ def set_as_paid(self):

else:
payment_entry = self.create_payment_entry()
self.make_invoice()
if self.make_sales_invoice:
self.make_invoice()

return payment_entry

Expand Down Expand Up @@ -416,9 +408,6 @@ def make_communication_entry(self):
)
comm.insert(ignore_permissions=True)

def get_payment_success_url(self):
return self.payment_success_url

def create_subscription(self, payment_provider, gateway_controller, data):
if payment_provider == "stripe":
with payment_app_import_guard():
Expand Down Expand Up @@ -497,6 +486,10 @@ def make_payment_request(**args):
"party_type": args.get("party_type") or "Customer",
"party": args.get("party") or ref_doc.get("customer"),
"bank_account": bank_account,
"make_sales_invoice": args.order_type == "Shopping Cart",
"mute_email": args.mute_email
or args.order_type == "Shopping Cart"
or gateway_account.get("payment_channel", "Email") != "Email",
}
)

Expand All @@ -511,9 +504,6 @@ def make_payment_request(**args):
for dimension in get_accounting_dimensions():
pr.update({dimension: ref_doc.get(dimension)})

if args.order_type == "Shopping Cart" or args.mute_email:
pr.flags.mute_email = True

pr.insert(ignore_permissions=True)
if args.submit_doc:
pr.submit()
Expand Down Expand Up @@ -596,7 +586,7 @@ def get_payment_gateway_account(args):
return frappe.db.get_value(
"Payment Gateway Account",
args,
["name", "payment_gateway", "payment_account", "message"],
["name", "payment_gateway", "payment_account", "payment_channel", "message"],
as_dict=1,
)

Expand Down
7 changes: 5 additions & 2 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1962,11 +1962,14 @@ def test_sales_order_advance_payment_status(self):

# Flow progressing to SI with payment entries "moved" from SO to SI
so = make_sales_order(qty=1, rate=100, do_not_submit=True)
so.order_type = "Shopping Cart" # trigger auto Sales Invoice creation
# no-op; for optical consistency with how a webshop SO would look like
so.order_type = "Shopping Cart"
so.submit()
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Not Requested")

pr = make_payment_request(dt=so.doctype, dn=so.name, submit_doc=True, return_doc=True)
pr = make_payment_request(
dt=so.doctype, dn=so.name, order_type="Shopping Cart", submit_doc=True, return_doc=True
)
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Requested")

pe = pr.set_as_paid()
Expand Down

0 comments on commit 7b03243

Please sign in to comment.