fix: Show popup to employees with same phone number

This commit is contained in:
Suraj Shetty
2019-08-05 11:32:51 +05:30
parent 35c4b78e66
commit 0957480305
4 changed files with 40 additions and 27 deletions

View File

@@ -28,28 +28,28 @@ class CallLog(Document):
self.trigger_call_popup() self.trigger_call_popup()
def trigger_call_popup(self): def trigger_call_popup(self):
employee_email = get_employee_email(self.to) employee_emails = get_employee_emails(self.to)
if employee_email: for email in employee_emails:
frappe.publish_realtime('show_call_popup', self, user=employee_email) frappe.publish_realtime('show_call_popup', self, user=email)
@frappe.whitelist() @frappe.whitelist()
def add_call_summary(call_log, summary): def add_call_summary(call_log, summary):
doc = frappe.get_doc('Call Log', call_log) doc = frappe.get_doc('Call Log', call_log)
doc.add_comment('Comment', frappe.bold(_('Call Summary')) + '<br><br>' + summary) 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 if not number: return
number = number.lstrip('0')
employee = frappe.cache().hget('employee_with_number', number) employee_emails = frappe.cache().hget('employees_with_number', number)
if employee: return employee if employee_emails: return employee_emails
employees = frappe.get_all('Employee', or_filters={ employees = frappe.get_all('Employee', filters={
'phone': ['like', '%{}'.format(number)], 'cell_number': ['like', '%{}'.format(number.lstrip('0'))],
'user_id': ['!=', ''] 'user_id': ['!=', '']
}, fields=['user_id'], limit=1) }, fields=['user_id'])
employee = employees[0].user_id if employees else None employee_emails = [employee.user_id for employee in employees]
frappe.cache().hset('employee_with_number', number, employee) frappe.cache().hset('employees_with_number', number, employee_emails)
return employee return employee

View File

@@ -7,8 +7,8 @@ def get_last_interaction(contact=None, lead=None):
if not contact and not lead: return if not contact and not lead: return
last_communication = {} last_communication = None
last_issue = {} last_issue = None
if contact: if contact:
query_condition = '' query_condition = ''
contact = frappe.get_doc('Contact', contact) contact = frappe.get_doc('Contact', contact)
@@ -32,8 +32,8 @@ def get_last_interaction(contact=None, lead=None):
if lead: if lead:
last_communication = frappe.get_all('Communication', filters={ last_communication = frappe.get_all('Communication', filters={
'reference_doctype': 'Contact', 'reference_doctype': 'Lead',
'reference_name': contact, 'reference_name': lead,
'sent_or_received': 'Received' 'sent_or_received': 'Received'
}, fields=['name', 'content'], limit=1) }, fields=['name', 'content'], limit=1)

View File

@@ -76,6 +76,7 @@ class Employee(NestedSet):
if self.user_id: if self.user_id:
self.update_user() self.update_user()
self.update_user_permissions() self.update_user_permissions()
self.reset_employee_emails_cache()
def update_user_permissions(self): def update_user_permissions(self):
if not self.create_user_permission: return if not self.create_user_permission: return
@@ -214,6 +215,13 @@ class Employee(NestedSet):
doc.validate_employee_creation() doc.validate_employee_creation()
doc.db_set("employee", self.name) 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): def get_timeline_data(doctype, name):
'''Return timeline for attendance''' '''Return timeline for attendance'''
return dict(frappe.db.sql('''select unix_timestamp(attendance_date), count(*) return dict(frappe.db.sql('''select unix_timestamp(attendance_date), count(*)

View File

@@ -49,18 +49,19 @@ class CallPopup {
'fieldtype': 'Section Break', 'fieldtype': 'Section Break',
'label': __('Activity'), 'label': __('Activity'),
'depends_on': () => this.get_caller_name() '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', 'fieldtype': 'Small Text',
'label': __('Last Communication'), 'label': __('Last Communication'),
'fieldname': 'last_communication', 'fieldname': 'last_communication',
'read_only': true, 'read_only': true,
'default': `<i class="text-muted">${__('No communication found.')}<i>` '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': 'Section Break',
}, { }, {
@@ -79,13 +80,15 @@ class CallPopup {
}).then(() => { }).then(() => {
this.close_modal(); this.close_modal();
frappe.show_alert({ frappe.show_alert({
message: `${__('Call Summary Saved')} message: `
${__('Call Summary Saved')}
<br> <br>
<a <a
class="text-small text-muted" class="text-small text-muted"
href="#Form/Call Log/${this.call_log.name}"> href="#Form/Call Log/${this.call_log.name}">
${__('View call log')} ${__('View call log')}
</a>`, </a>
`,
indicator: 'green' indicator: 'green'
}); });
}); });
@@ -163,9 +166,11 @@ class CallPopup {
const issue = data.last_issue; const issue = data.last_issue;
const issue_field = this.dialog.get_field("last_issue"); const issue_field = this.dialog.get_field("last_issue");
issue_field.set_value(issue.subject); issue_field.set_value(issue.subject);
issue_field.$wrapper.append(`<a class="text-medium" href="#List/Issue?customer=${issue.customer}"> issue_field.$wrapper.append(`
${__('View all issues from {0}', [issue.customer])} <a class="text-medium" href="#List/Issue?customer=${issue.customer}">
</a>`); ${__('View all issues from {0}', [issue.customer])}
</a>
`);
} }
}); });
} }