From d4edd284e699c1d6626c46e52ba10c8edaf84c73 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Fri, 9 Aug 2019 19:23:04 +0530 Subject: [PATCH] fix: Set Contact or Lead for call log - Set contact or lead to call log on new Contact or Lead creation --- .../doctype/call_log/call_log.py | 24 ++++++++++++++++++- erpnext/hooks.py | 8 +++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py index fdbdb634a0..c9fdfbe447 100644 --- a/erpnext/communication/doctype/call_log/call_log.py +++ b/erpnext/communication/doctype/call_log/call_log.py @@ -61,4 +61,26 @@ def get_employees_with_number(number): employee_emails = [employee.user_id for employee in employees] frappe.cache().hset('employees_with_number', number, employee_emails) - return employee \ No newline at end of file + return employee + +def set_caller_information(doc, state): + '''Called from hoooks on creation of Lead or Contact''' + if doc.doctype not in ['Lead', 'Contact']: return + + numbers = [doc.get('phone'), doc.get('mobile_no')] + for_doc = doc.doctype.lower() + + for number in numbers: + if not number: continue + print(number) + filters = frappe._dict({ + 'from': ['like', '%{}'.format(number.lstrip('0'))], + for_doc: '' + }) + + logs = frappe.get_all('Call Log', filters=filters) + + for log in logs: + call_log = frappe.get_doc('Call Log', log.name) + call_log.set(for_doc, doc.name) + call_log.save(ignore_permissions=True) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 47d1a68efc..be9a4fb264 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -231,8 +231,12 @@ doc_events = { ('Sales Invoice', 'Purchase Invoice', 'Delivery Note'): { 'validate': 'erpnext.regional.india.utils.set_place_of_supply' }, - "Contact":{ - "on_trash": "erpnext.support.doctype.issue.issue.update_issue" + "Contact": { + "on_trash": "erpnext.support.doctype.issue.issue.update_issue", + "after_insert": "erpnext.communication.doctype.call_log.call_log.set_caller_information" + }, + "Lead": { + "after_insert": "erpnext.communication.doctype.call_log.call_log.set_caller_information" }, "Email Unsubscribe": { "after_insert": "erpnext.crm.doctype.email_campaign.email_campaign.unsubscribe_recipient"