fix: Show popup to employees with same phone number
diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py
index fae649c..cf5c12e 100644
--- a/erpnext/communication/doctype/call_log/call_log.py
+++ b/erpnext/communication/doctype/call_log/call_log.py
@@ -28,28 +28,28 @@
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')) + '<br><br>' + 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 7e9a8f4..c809469 100644
--- a/erpnext/crm/doctype/utils.py
+++ b/erpnext/crm/doctype/utils.py
@@ -7,8 +7,8 @@
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 @@
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 cf418b0..67f7443 100755
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -76,6 +76,7 @@
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 @@
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 847b501..5278b32 100644
--- a/erpnext/public/js/call_popup/call_popup.js
+++ b/erpnext/public/js/call_popup/call_popup.js
@@ -51,17 +51,18 @@
'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': `<i class="text-muted">${__('No issue has been raised by the caller.')}<i>`
+ }, {
+ 'fieldtype': 'Small Text',
'label': __('Last Communication'),
'fieldname': 'last_communication',
'read_only': true,
'default': `<i class="text-muted">${__('No communication found.')}<i>`
}, {
- 'fieldtype': 'Small Text',
- 'label': __('Last Issue'),
- 'fieldname': 'last_issue',
- 'read_only': true,
- 'default': `<i class="text-muted">${__('No issue raised by the customer.')}<i>`
- }, {
'fieldtype': 'Section Break',
}, {
'fieldtype': 'Small Text',
@@ -79,13 +80,15 @@
}).then(() => {
this.close_modal();
frappe.show_alert({
- message: `${__('Call Summary Saved')}
+ message: `
+ ${__('Call Summary Saved')}
<br>
<a
class="text-small text-muted"
href="#Form/Call Log/${this.call_log.name}">
${__('View call log')}
- </a>`,
+ </a>
+ `,
indicator: 'green'
});
});
@@ -163,9 +166,11 @@
const issue = data.last_issue;
const issue_field = this.dialog.get_field("last_issue");
issue_field.set_value(issue.subject);
- issue_field.$wrapper.append(`<a class="text-medium" href="#List/Issue?customer=${issue.customer}">
- ${__('View all issues from {0}', [issue.customer])}
- </a>`);
+ issue_field.$wrapper.append(`
+ <a class="text-medium" href="#List/Issue?customer=${issue.customer}">
+ ${__('View all issues from {0}', [issue.customer])}
+ </a>
+ `);
}
});
}