From a8ec43bcf80fae817e3782c8d3e214ab639d56a3 Mon Sep 17 00:00:00 2001 From: Diptanil Saha Date: Wed, 9 Sep 2026 15:37:55 +0530 Subject: [PATCH] fix(selling): add email permission check on `send_emails` (#58935) --- erpnext/selling/doctype/customer/customer.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 5b896b674bc..e014490eda0 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -558,11 +558,8 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False, # if the current user does not have permissions to override credit limit, # prompt them to send out an email to the controller users - frappe.msgprint( - message, - title=_("Credit Limit Crossed"), - raise_exception=1, - primary_action={ + primary_action = ( + { "label": "Send Email", "server_action": "erpnext.selling.doctype.customer.customer.send_emails", "hide_on_success": True, @@ -572,7 +569,16 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False, "credit_limit": credit_limit, "credit_controller_users_list": credit_controller_users, }, - }, + } + if frappe.has_permission("Customer", ptype="email", doc=customer) + else None + ) + + frappe.msgprint( + message, + title=_("Credit Limit Crossed"), + raise_exception=1, + primary_action=primary_action, ) @@ -580,6 +586,7 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False, def send_emails( customer: str, customer_outstanding: float, credit_limit: float, credit_controller_users_list: str | list ): + frappe.has_permission("Customer", ptype="email", doc=customer, throw=True) credit_controller_users_list = frappe.parse_json(credit_controller_users_list) subject = _("Credit limit reached for customer {0}").format(customer) message = _("Credit limit has been crossed for customer {0} ({1}/{2})").format(