From 0b53fa6af60e3fa65d11b8da2d07a6cf074a5795 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Mon, 21 Oct 2024 13:53:40 +0530 Subject: [PATCH 1/2] fix: only show pay button for specific doctype in portal --- .../payment_request/payment_request.py | 21 +++++++++++----- erpnext/templates/pages/order.py | 25 ++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 25c64f456fe..1f6f78d17f5 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -27,11 +27,14 @@ def _get_payment_gateway_controller(*args, **kwargs): return get_payment_gateway_controller(*args, **kwargs) -def _get_shopping_cart_settings(): - with webshop_app_import_guard(): - from webshop.webshop.shopping_cart.cart import 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): @@ -638,7 +641,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 21d4b860d1f..f9739410fa8 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 -- GitLab From 383e16a74c96ea22c838dfa3f39af53de6f9a73b Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Sat, 26 Oct 2024 14:55:21 +0200 Subject: [PATCH 2/2] fix: merge conflict --- .../accounts/doctype/payment_request/payment_request.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 1f6f78d17f5..99c83b38de0 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -27,6 +27,13 @@ def _get_payment_gateway_controller(*args, **kwargs): return get_payment_gateway_controller(*args, **kwargs) +def _get_shopping_cart_settings(): + with webshop_app_import_guard(): + from webshop.webshop.shopping_cart.cart import get_shopping_cart_settings + + return get_shopping_cart_settings() + + ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST = [ "Sales Order", "Purchase Order", -- GitLab