diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py index fae649cd508..cf5c12e0dce 100644 --- a/erpnext/communication/doctype/call_log/call_log.py +++ b/erpnext/communication/doctype/call_log/call_log.py @@ -28,28 +28,28 @@ class CallLog(Document): self.trigger_call_popup() def trigger_call_popup(self): - employee_email = get_employee_email(self.to) - if employee_email: - frappe.publish_realtime('show_call_popup', self, user=employee_email) + employee_emails = get_employee_emails(self.to) + for email in employee_emails: + frappe.publish_realtime('show_call_popup', self, user=email) @frappe.whitelist() def add_call_summary(call_log, summary): doc = frappe.get_doc('Call Log', call_log) doc.add_comment('Comment', frappe.bold(_('Call Summary')) + '

' + summary) -def get_employee_email(number): +def get_employee_emails(number): + '''Returns employee's emails of employees that have passed phone number''' if not number: return - number = number.lstrip('0') - employee = frappe.cache().hget('employee_with_number', number) - if employee: return employee + employee_emails = frappe.cache().hget('employees_with_number', number) + if employee_emails: return employee_emails - employees = frappe.get_all('Employee', or_filters={ - 'phone': ['like', '%{}'.format(number)], + employees = frappe.get_all('Employee', filters={ + 'cell_number': ['like', '%{}'.format(number.lstrip('0'))], 'user_id': ['!=', ''] - }, fields=['user_id'], limit=1) + }, fields=['user_id']) - employee = employees[0].user_id if employees else None - frappe.cache().hset('employee_with_number', number, employee) + 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 diff --git a/erpnext/crm/doctype/utils.py b/erpnext/crm/doctype/utils.py index 7e9a8f46883..c809469efe6 100644 --- a/erpnext/crm/doctype/utils.py +++ b/erpnext/crm/doctype/utils.py @@ -7,8 +7,8 @@ def get_last_interaction(contact=None, lead=None): if not contact and not lead: return - last_communication = {} - last_issue = {} + last_communication = None + last_issue = None if contact: query_condition = '' contact = frappe.get_doc('Contact', contact) @@ -32,8 +32,8 @@ def get_last_interaction(contact=None, lead=None): if lead: last_communication = frappe.get_all('Communication', filters={ - 'reference_doctype': 'Contact', - 'reference_name': contact, + 'reference_doctype': 'Lead', + 'reference_name': lead, 'sent_or_received': 'Received' }, fields=['name', 'content'], limit=1) diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index cf418b0e8fe..67f7443efd6 100755 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -76,6 +76,7 @@ class Employee(NestedSet): if self.user_id: self.update_user() self.update_user_permissions() + self.reset_employee_emails_cache() def update_user_permissions(self): if not self.create_user_permission: return @@ -214,6 +215,13 @@ class Employee(NestedSet): doc.validate_employee_creation() doc.db_set("employee", self.name) + def reset_employee_emails_cache(self): + prev_doc = self.get_doc_before_save() + if (self.cell_number != prev_doc.cell_number or + self.user_id != prev_doc.user_id): + frappe.cache().hdel('employees_with_number', prev_doc.cell_number) + frappe.cache().hdel('employees_with_number', self.cell_number) + def get_timeline_data(doctype, name): '''Return timeline for attendance''' return dict(frappe.db.sql('''select unix_timestamp(attendance_date), count(*) diff --git a/erpnext/public/js/call_popup/call_popup.js b/erpnext/public/js/call_popup/call_popup.js index 847b501ea37..5278b322a4e 100644 --- a/erpnext/public/js/call_popup/call_popup.js +++ b/erpnext/public/js/call_popup/call_popup.js @@ -49,18 +49,19 @@ class CallPopup { 'fieldtype': 'Section Break', 'label': __('Activity'), 'depends_on': () => this.get_caller_name() + }, { + 'fieldtype': 'Small Text', + 'label': __('Last Issue'), + 'fieldname': 'last_issue', + 'read_only': true, + 'depends_on': () => this.call_log.contact, + 'default': `${__('No issue has been raised by the caller.')}` }, { 'fieldtype': 'Small Text', 'label': __('Last Communication'), 'fieldname': 'last_communication', 'read_only': true, 'default': `${__('No communication found.')}` - }, { - 'fieldtype': 'Small Text', - 'label': __('Last Issue'), - 'fieldname': 'last_issue', - 'read_only': true, - 'default': `${__('No issue raised by the customer.')}` }, { 'fieldtype': 'Section Break', }, { @@ -79,13 +80,15 @@ class CallPopup { }).then(() => { this.close_modal(); frappe.show_alert({ - message: `${__('Call Summary Saved')} + message: ` + ${__('Call Summary Saved')}
${__('View call log')} - `, + + `, indicator: 'green' }); }); @@ -163,9 +166,11 @@ class CallPopup { const issue = data.last_issue; const issue_field = this.dialog.get_field("last_issue"); issue_field.set_value(issue.subject); - issue_field.$wrapper.append(` - ${__('View all issues from {0}', [issue.customer])} - `); + issue_field.$wrapper.append(` + + ${__('View all issues from {0}', [issue.customer])} + + `); } }); }