From 7c67c38bc555402c33f232d70458a24048a33673 Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Tue, 28 Apr 2020 16:08:52 +0530 Subject: [PATCH 1/2] fix: update lead if contact details are changed --- erpnext/crm/utils.py | 24 ++++++++++++++++++++++++ erpnext/hooks.py | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 erpnext/crm/utils.py diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py new file mode 100644 index 00000000000..72d778e9568 --- /dev/null +++ b/erpnext/crm/utils.py @@ -0,0 +1,24 @@ +import frappe + + +def update_lead_phone_numbers(contact, method): + if contact.phone_nos: + contact_lead = contact.get_link_for("Lead") + if contact_lead: + phone = mobile_no = contact.phone_nos[0].phone + + if len(contact.phone_nos) > 1: + # get the default phone number + primary_phones = [phone.phone for phone in contact.phone_nos if phone.is_primary_phone] + if primary_phones: + phone = primary_phones[0] + + # get the default mobile number + primary_mobile_nos = [phone.phone for phone in contact.phone_nos if phone.is_primary_mobile_no] + if primary_mobile_nos: + mobile_no = primary_mobile_nos[0] + + lead = frappe.get_doc("Lead", contact_lead) + lead.phone = phone + lead.mobile_no = mobile_no + lead.save() diff --git a/erpnext/hooks.py b/erpnext/hooks.py index d387f19692e..6712842948e 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -256,7 +256,8 @@ doc_events = { }, "Contact": { "on_trash": "erpnext.support.doctype.issue.issue.update_issue", - "after_insert": "erpnext.communication.doctype.call_log.call_log.set_caller_information" + "after_insert": "erpnext.communication.doctype.call_log.call_log.set_caller_information", + "validate": "erpnext.crm.utils.update_lead_phone_numbers" }, "Lead": { "after_insert": "erpnext.communication.doctype.call_log.call_log.set_caller_information" From bd969477b1752a95943dae54cf09f706024390bd Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Wed, 29 Apr 2020 13:09:16 +0530 Subject: [PATCH 2/2] fix: AttributeError --- erpnext/crm/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py index 72d778e9568..38bf79e5fcb 100644 --- a/erpnext/crm/utils.py +++ b/erpnext/crm/utils.py @@ -9,12 +9,12 @@ def update_lead_phone_numbers(contact, method): if len(contact.phone_nos) > 1: # get the default phone number - primary_phones = [phone.phone for phone in contact.phone_nos if phone.is_primary_phone] + primary_phones = [phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_phone] if primary_phones: phone = primary_phones[0] # get the default mobile number - primary_mobile_nos = [phone.phone for phone in contact.phone_nos if phone.is_primary_mobile_no] + primary_mobile_nos = [phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_mobile_no] if primary_mobile_nos: mobile_no = primary_mobile_nos[0]