[fix] redirect to payment url if paying via web portal (#10265)

* [fix] redirect to payment url if paying via web portal

* [fix] test case fix

* [fix] test case fixes
This commit is contained in:
Saurabh 2017-08-08 11:29:11 +05:30 committed by Nabin Hait
parent 255c5f4407
commit 3a4b6c2cba
4 changed files with 12 additions and 18 deletions

View File

@ -37,10 +37,11 @@ class PaymentRequest(Document):
self.make_communication_entry()
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
if hasattr(ref_doc, "order_type") and getattr(ref_doc, "order_type") == "Shopping Cart":
if (hasattr(ref_doc, "order_type") and getattr(ref_doc, "order_type") == "Shopping Cart") \
or self.flags.mute_email:
send_mail = False
if send_mail and not self.flags.mute_email:
if send_mail:
self.set_payment_request_url()
self.send_email()
@ -50,7 +51,7 @@ class PaymentRequest(Document):
def make_invoice(self):
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
if hasattr(ref_doc, "order_type") and getattr(ref_doc, "order_type") == "Shopping Cart":
if (hasattr(ref_doc, "order_type") and getattr(ref_doc, "order_type") == "Shopping Cart"):
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
si = make_sales_invoice(self.reference_name, ignore_permissions=True)
si = si.insert(ignore_permissions=True)
@ -216,12 +217,9 @@ def make_payment_request(**args):
"""Make payment request"""
args = frappe._dict(args)
ref_doc = frappe.get_doc(args.dt, args.dn)
gateway_account = get_gateway_details(args) or frappe._dict()
grand_total = get_amount(ref_doc, args.dt)
gateway_account = get_gateway_details(args) or frappe._dict()
existing_payment_request = frappe.db.get_value("Payment Request",
{"reference_doctype": args.dt, "reference_name": args.dn, "docstatus": ["!=", 2]})
@ -244,22 +242,19 @@ def make_payment_request(**args):
"reference_name": args.dn
})
if args.return_doc:
return pr
if args.mute_email:
if args.order_type == "Shopping Cart" or args.mute_email:
pr.flags.mute_email = True
if args.submit_doc:
pr.insert(ignore_permissions=True)
pr.submit()
if hasattr(ref_doc, "order_type") and getattr(ref_doc, "order_type") == "Shopping Cart":
if args.order_type == "Shopping Cart":
frappe.db.commit()
frappe.local.response["type"] = "redirect"
frappe.local.response["location"] = pr.get_payment_url()
if not args.cart:
if args.return_doc:
return pr
return pr.as_dict()

View File

@ -70,7 +70,7 @@ class TestPaymentRequest(unittest.TestCase):
so_inr = make_sales_order(currency="INR")
pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com",
mute_email=1, submit_doc=1)
mute_email=1, submit_doc=1, return_doc=1)
pe = pr.set_as_paid()
so_inr = frappe.get_doc("Sales Order", so_inr.name)
@ -81,7 +81,7 @@ class TestPaymentRequest(unittest.TestCase):
currency="USD", conversion_rate=50)
pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com",
mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1)
mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1, return_doc=1)
pe = pr.set_as_paid()

View File

@ -46,6 +46,7 @@ def get_product_info(item_code):
}
def get_qty_in_stock(item_code, template_item_code):
in_stock, stock_qty = 0, ''
warehouse = frappe.db.get_value("Item", item_code, "website_warehouse")
if not warehouse and template_item_code and template_item_code != item_code:
warehouse = frappe.db.get_value("Item", template_item_code, "website_warehouse")
@ -55,8 +56,6 @@ def get_qty_in_stock(item_code, template_item_code):
item_code=%s and warehouse=%s""", (item_code, warehouse))
if stock_qty:
in_stock = stock_qty[0][0] > 0 and 1 or 0
else:
in_stock = 0
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty})

View File

@ -79,7 +79,7 @@
or (doc.doctype=="Sales Invoice" and doc.outstanding_amount > 0) %}
<div class="page-header-actions-block" data-html-block="header-actions">
<p>
<a href="/api/method/erpnext.accounts.doctype.payment_request.payment_request.make_payment_request?dn={{ doc.name }}&dt={{ doc.doctype }}&submit_doc=1"
<a href="/api/method/erpnext.accounts.doctype.payment_request.payment_request.make_payment_request?dn={{ doc.name }}&dt={{ doc.doctype }}&submit_doc=1&order_type=Shopping Cart"
class="btn btn-primary btn-sm">{{ _("Pay") }} {{ doc.get_formatted("grand_total") }} </a>
</p>
</div>