diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 25c64f456feab5ccb71e658955b765aaf624d4ba..99c83b38de0c16b2694195338da7ac50b43831ac 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -34,6 +34,16 @@ def _get_shopping_cart_settings(): return get_shopping_cart_settings() +ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST = [ + "Sales Order", + "Purchase Order", + "Sales Invoice", + "Purchase Invoice", + "POS Invoice", + "Fees", +] + + class PaymentRequest(Document): # begin: auto-generated types # This code is auto-generated. Do not modify anything in this block. @@ -638,7 +648,13 @@ class PaymentRequest(Document): def make_payment_request(*args, **kwargs): """Make payment request""" args = frappe._dict(kwargs) - ref_doc = frappe.get_doc(args.dt, args.dn) + ref_doc = args.ref_doc or frappe.get_doc(args.dt, args.dn) + + if ref_doc.doctype not in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST: + frappe.throw( + _("Payment Requests cannot be created against: {0}").format(frappe.bold(ref_doc.doctype)) + ) + grand_total = flt(args.grand_total) or get_amount(ref_doc) if args.loyalty_points and args.dt == "Sales Order": diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py index 21d4b860d1fa891c1431821fae3f40efbb986aa8..f9739410fa8fa7f92b7bb0b56e7ed9ee4628a9a0 100644 --- a/erpnext/templates/pages/order.py +++ b/erpnext/templates/pages/order.py @@ -4,6 +4,11 @@ import frappe from frappe import _ +from erpnext.accounts.doctype.payment_request.payment_request import ( + ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST, + get_amount, +) + def get_context(context): context.no_cache = 1 @@ -34,9 +39,7 @@ def get_context(context): context.available_loyalty_points = 0.0 if context.doc.get("customer"): # check for the loyalty program of the customer - customer_loyalty_program = frappe.db.get_value( - "Customer", context.doc.customer, "loyalty_program" - ) + customer_loyalty_program = frappe.db.get_value("Customer", context.doc.customer, "loyalty_program") if customer_loyalty_program: from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( @@ -64,3 +67,19 @@ def get_attachments(dt, dn): fields=["name", "file_name", "file_url", "is_private"], filters={"attached_to_name": dn, "attached_to_doctype": dt, "is_private": 0}, ) + + +def get_payment_details(doc): + show_pay_button, amount = ( + ( + "payments" in frappe.get_installed_apps() + and frappe.db.get_single_value("Buying Settings", "show_pay_button") + and doc.doctype in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST + ), + 0, + ) + if not show_pay_button: + return show_pay_button, amount + + amount = get_amount(doc) + return bool(amount), amount