From d2e5b2aa1d22cdcaccc62b412732b8d12f9b1aa3 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Tue, 22 Oct 2024 19:49:37 +0530 Subject: [PATCH] fix: only show pay button for specific doctype in portal --- .../doctype/payment_request/payment_request.py | 12 ++++++++++++ erpnext/templates/pages/order.py | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index fd07551897a..462cae95ba5 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -20,6 +20,15 @@ from erpnext.accounts.party import get_party_account, get_party_bank_account from erpnext.accounts.utils import get_account_currency, get_currency_precision from erpnext.utilities import payment_app_import_guard +ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST = [ + "Sales Order", + "Purchase Order", + "Sales Invoice", + "Purchase Invoice", + "POS Invoice", + "Fees", +] + def _get_payment_gateway_controller(*args, **kwargs): with payment_app_import_guard(): @@ -525,6 +534,9 @@ def make_payment_request(**args): args = frappe._dict(args) + if args.dt not in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST: + frappe.throw(_("Payment Requests cannot be created against: {0}").format(frappe.bold(args.dt))) + ref_doc = frappe.get_doc(args.dt, args.dn) gateway_account = get_gateway_details(args) or frappe._dict() diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py index 505399f4a5b..dca5a0c7497 100644 --- a/erpnext/templates/pages/order.py +++ b/erpnext/templates/pages/order.py @@ -4,6 +4,10 @@ import frappe from frappe import _ +from erpnext.accounts.doctype.payment_request.payment_request import ( + ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST, +) + def get_context(context): context.no_cache = 1 @@ -46,8 +50,10 @@ def get_context(context): ) context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points")) - context.show_pay_button = "payments" in frappe.get_installed_apps() and frappe.db.get_single_value( - "Buying Settings", "show_pay_button" + context.show_pay_button = ( + "payments" in frappe.get_installed_apps() + and frappe.db.get_single_value("Buying Settings", "show_pay_button") + and context.doc.doctype in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST ) context.show_make_pi_button = False if context.doc.get("supplier"):