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()
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

View File

@ -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)

View File

@ -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(*)

View File

@ -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': `<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',
}, {
@ -79,13 +80,15 @@ class CallPopup {
}).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 @@ 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(`<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>
`);
}
});
}