fix: Make required changes

This commit is contained in:
Suraj Shetty 2019-07-01 14:28:59 +05:30
parent 1431bf2a3c
commit 502565ff56
3 changed files with 33 additions and 29 deletions

View File

@ -82,12 +82,14 @@ def get_employee_emails_for_popup(communication_medium):
now_time = frappe.utils.nowtime() now_time = frappe.utils.nowtime()
weekday = frappe.utils.get_weekday() weekday = frappe.utils.get_weekday()
available_employee_groups = frappe.db.sql_list("""SELECT `employee_group` available_employee_groups = frappe.get_all("Communication Medium Timeslot", filters={
FROM `tabCommunication Medium Timeslot` 'day_of_week': weekday,
WHERE `day_of_week` = %s 'parent': communication_medium,
AND `parent` = %s 'from_time': ['<=', now_time],
AND %s BETWEEN `from_time` AND `to_time` 'to_time': ['>=', now_time],
""", (weekday, communication_medium, now_time)) }, fields=['employee_group'], debug=1)
available_employee_groups = tuple([emp.employee_group for emp in available_employee_groups])
employees = frappe.get_all('Employee Group Table', filters={ employees = frappe.get_all('Employee Group Table', filters={
'parent': ['in', available_employee_groups] 'parent': ['in', available_employee_groups]

View File

@ -6,26 +6,29 @@ import requests
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_missed_call # api/method/erpnext.erpnext_integrations.exotel_integration.handle_missed_call
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def handle_incoming_call(*args, **kwargs): def handle_incoming_call(**kwargs):
exotel_settings = get_exotel_settings() exotel_settings = get_exotel_settings()
if not exotel_settings.enabled: return if not exotel_settings.enabled: return
status = kwargs.get('Status') call_payload = kwargs
status = call_payload.get('Status')
if status == 'free': if status == 'free':
return return
create_call_log(kwargs) call_log = get_call_log(call_payload)
if not call_log:
create_call_log(call_payload)
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def handle_end_call(*args, **kwargs): def handle_end_call(**kwargs):
update_call_log(kwargs, 'Completed') update_call_log(kwargs, 'Completed')
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def handle_missed_call(*args, **kwargs): def handle_missed_call(**kwargs):
update_call_log(kwargs, 'Missed') update_call_log(kwargs, 'Missed')
def update_call_log(call_payload, status): def update_call_log(call_payload, status):
call_log = get_call_log(call_payload, False) call_log = get_call_log(call_payload)
if call_log: if call_log:
call_log.status = status call_log.status = status
call_log.duration = call_payload.get('DialCallDuration') or 0 call_log.duration = call_payload.get('DialCallDuration') or 0
@ -34,25 +37,24 @@ def update_call_log(call_payload, status):
frappe.db.commit() frappe.db.commit()
return call_log return call_log
def get_call_log(call_payload, create_new_if_not_found=True): def get_call_log(call_payload):
call_log = frappe.get_all('Call Log', { call_log = frappe.get_all('Call Log', {
'id': call_payload.get('CallSid'), 'id': call_payload.get('CallSid'),
}, limit=1) }, limit=1)
if call_log: if call_log:
return frappe.get_doc('Call Log', call_log[0].name) return frappe.get_doc('Call Log', call_log[0].name)
elif create_new_if_not_found:
call_log = frappe.new_doc('Call Log')
call_log.id = call_payload.get('CallSid')
call_log.to = call_payload.get('CallTo')
call_log.medium = call_payload.get('To')
call_log.status = 'Ringing'
setattr(call_log, 'from', call_payload.get('CallFrom'))
call_log.save(ignore_permissions=True)
frappe.db.commit()
return call_log
create_call_log = get_call_log def create_call_log(call_payload):
call_log = frappe.new_doc('Call Log')
call_log.id = call_payload.get('CallSid')
call_log.to = call_payload.get('CallTo')
call_log.medium = call_payload.get('To')
call_log.status = 'Ringing'
setattr(call_log, 'from', call_payload.get('CallFrom'))
call_log.save(ignore_permissions=True)
frappe.db.commit()
return call_log
@frappe.whitelist() @frappe.whitelist()
def get_call_status(call_id): def get_call_status(call_id):

View File

@ -64,8 +64,8 @@ class CallPopup {
} }
make_caller_info_section() { make_caller_info_section() {
const wrapper = this.dialog.fields_dict['caller_info'].$wrapper; const wrapper = this.dialog.get_field('caller_info').$wrapper;
wrapper.append('<div class="text-muted"> Loading... </div>'); wrapper.append(`<div class="text-muted"> ${__("Loading...")} </div>`);
frappe.xcall('erpnext.crm.doctype.utils.get_document_with_phone_number', { frappe.xcall('erpnext.crm.doctype.utils.get_document_with_phone_number', {
'number': this.caller_number 'number': this.caller_number
}).then(contact_doc => { }).then(contact_doc => {
@ -88,7 +88,7 @@ class CallPopup {
<button <button
class="margin-left btn btn-new btn-default btn-xs" class="margin-left btn btn-new btn-default btn-xs"
data-doctype="Contact" data-doctype="Contact"
title="Make New Contact"> title=${__("Make New Contact")}>
<i class="octicon octicon-plus text-medium"></i> <i class="octicon octicon-plus text-medium"></i>
</button> </button>
</div> </div>
@ -172,7 +172,7 @@ class CallPopup {
'number': this.caller_number, 'number': this.caller_number,
'reference_doc': this.contact 'reference_doc': this.contact
}).then(data => { }).then(data => {
const comm_field = this.dialog.fields_dict["last_communication"]; const comm_field = this.dialog.get_field('last_communication');
if (data.last_communication) { if (data.last_communication) {
const comm = data.last_communication; const comm = data.last_communication;
comm_field.set_value(comm.content); comm_field.set_value(comm.content);
@ -180,7 +180,7 @@ class CallPopup {
if (data.last_issue) { if (data.last_issue) {
const issue = data.last_issue; const issue = data.last_issue;
const issue_field = this.dialog.fields_dict["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(`<a class="text-medium" href="#List/Issue?customer=${issue.customer}">
${__('View all issues from {0}', [issue.customer])} ${__('View all issues from {0}', [issue.customer])}