Added modal to Action button on Lead DocType form to allow users to add Leads to Email Groups for newsletters and minor changes to CSS

This commit is contained in:
Jeremy Rangel
2025-06-05 00:54:17 -07:00
parent ca3ab820b5
commit e301150a2f
4 changed files with 79 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import frappe
from frappe.utils import today
from frappe import _
@frappe.whitelist()
def add_lead_to_campaign(lead_name, campaign_name, start_date=None):
@ -29,3 +30,32 @@ def add_lead_to_campaign(lead_name, campaign_name, start_date=None):
frappe.db.commit()
return {"status": "success", "message": "Email Campaign created"}
@frappe.whitelist()
def add_lead_to_email_group(lead_name, email_group):
if not lead_name or not email_group:
return {"status": "error", "message": _("Missing required parameters.")}
lead = frappe.get_doc("Lead", lead_name)
if not lead.email_id:
return {"status": "error", "message": _("Lead does not have an email address.")}
# Check if already added
exists = frappe.db.exists(
"Email Group Member",
{"email": lead.email_id, "email_group": email_group}
)
if exists:
return {"status": "error", "message": _("Lead is already in this Email Group.")}
# Add to email group
frappe.get_doc({
"doctype": "Email Group Member",
"email_group": email_group,
"email": lead.email_id,
"status": "Subscribed"
}).insert(ignore_permissions=True)
return {"status": "success"}