diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 196838ac4c9a..b0d450139745 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -159,12 +159,7 @@ def on_submit(self): 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() @@ -226,14 +221,12 @@ def on_cancel(self): ref_doc.set_total_advance_paid() 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: @@ -289,7 +282,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 @@ -422,9 +416,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(): @@ -503,6 +494,9 @@ 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.order_type == "Shopping Cart" + or gateway_account.get("payment_channel", default="Email") != "Email", } ) @@ -517,9 +511,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()