Added override for ERPNext updating a Lead's mobile_no field even if that phone number isn't defined as primary_mobile in the linked Contact
This commit is contained in:
Binary file not shown.
@ -27,6 +27,14 @@ scheduler_events = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Document Events
|
||||||
|
# Override Contact-> Validate to avoid setting non-mobile numbers as Lead mobile_no field
|
||||||
|
doc_events = {
|
||||||
|
"Contact": {
|
||||||
|
"validate": ["rangeldigital.utilities.contact.contact_hooks.update_lead_phone_numbers"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Disable default send_email_to_leads_or_contacts
|
# Disable default send_email_to_leads_or_contacts
|
||||||
after_install = "rangeldigital.utilities.install.after_install"
|
after_install = "rangeldigital.utilities.install.after_install"
|
||||||
|
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
import frappe
|
|
||||||
|
|
||||||
def after_install():
|
|
||||||
stop_erpnext_scheduled_send_email_job()
|
|
||||||
|
|
||||||
def stop_erpnext_scheduled_send_email_job():
|
|
||||||
# Get list of Scheduled Job Type docs with that method
|
|
||||||
job_docs = frappe.get_all(
|
|
||||||
"Scheduled Job Type",
|
|
||||||
filters={"method": "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts"},
|
|
||||||
limit_page_length=1
|
|
||||||
)
|
|
||||||
|
|
||||||
if not job_docs:
|
|
||||||
frappe.msgprint("Scheduled Job Type not found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
job_name = job_docs[0].name
|
|
||||||
job_doc = frappe.get_doc("Scheduled Job Type", job_name)
|
|
||||||
|
|
||||||
# Set stopped = 1
|
|
||||||
job_doc.stopped = 1
|
|
||||||
job_doc.save(ignore_permissions=True)
|
|
||||||
frappe.db.commit()
|
|
||||||
|
|
||||||
frappe.msgprint(f"Scheduled Job Type '{job_doc.method}' stopped successfully.")
|
|
||||||
Binary file not shown.
Binary file not shown.
27
rangeldigital/utilities/contact/contact_hooks.py
Normal file
27
rangeldigital/utilities/contact/contact_hooks.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
# Override ERPNext's hook that will set a Lead's mobile_no field based on a Contact's phone number even if it's not a mobile number
|
||||||
|
def update_lead_phone_numbers(contact, method):
|
||||||
|
if not contact.phone_nos:
|
||||||
|
return
|
||||||
|
|
||||||
|
contact_lead = contact.get_link_for("Lead")
|
||||||
|
if not contact_lead:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Get list of phones explicitly marked as primary mobile numbers
|
||||||
|
mobile_nos = [
|
||||||
|
phone_doc.phone
|
||||||
|
for phone_doc in contact.phone_nos
|
||||||
|
if phone_doc.is_primary_mobile_no
|
||||||
|
]
|
||||||
|
|
||||||
|
# If no mobile numbers were marked, clear Lead.mobile_no
|
||||||
|
if not mobile_nos:
|
||||||
|
lead = frappe.get_doc("Lead", contact_lead)
|
||||||
|
|
||||||
|
if lead.mobile_no:
|
||||||
|
# Optional: only unset if the current value matches one of the Contact's phones
|
||||||
|
contact_phone_values = {p.phone for p in contact.phone_nos}
|
||||||
|
if lead.mobile_no in contact_phone_values:
|
||||||
|
lead.db_set("mobile_no", None)
|
||||||
@ -15,7 +15,7 @@ def add_lead_to_campaign(lead_name, campaign_name, start_date=None):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
frappe.throw("This Lead is already part of an Email Campaign with this name.")
|
frappe.throw("This Lead is already in this Email Campaign")
|
||||||
|
|
||||||
doc = frappe.new_doc("Email Campaign")
|
doc = frappe.new_doc("Email Campaign")
|
||||||
doc.update({
|
doc.update({
|
||||||
|
|||||||
Reference in New Issue
Block a user