From 8ff135866f9a389de054f33b5443b4ab7f4157b5 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 | 22 ++++++++----------- erpnext/templates/pages/order.py | 20 +++++++++++------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index d92ec2f5235..1ecd1764cd1 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -29,11 +29,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): @@ -861,14 +864,7 @@ def make_payment_request(*args, **kwargs): args = frappe._dict(kwargs) ref_doc = args.ref_doc or frappe.get_doc(args.dt, args.dn) - if ref_doc.doctype not in [ - "Sales Order", - "Purchase Order", - "Sales Invoice", - "Purchase Invoice", - "POS Invoice", - "Fees", - ]: + 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)) ) diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py index 41b13845239..dcf3b046722 100644 --- a/erpnext/templates/pages/order.py +++ b/erpnext/templates/pages/order.py @@ -4,7 +4,10 @@ import frappe from frappe import _ -from erpnext.accounts.doctype.payment_request.payment_request import get_amount +from erpnext.accounts.doctype.payment_request.payment_request import ( + ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST, + get_amount, +) def get_context(context): @@ -36,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 ( @@ -67,10 +68,15 @@ def get_attachments(dt, dn): 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") - ), 0 + ( + "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 4394d0fc264e51ac4fe51a34679f9c39005d3d2a 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 1ecd1764cd1..325e8b58ab0 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -29,6 +29,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