From 502565ff5641ceb68409abe4c662a2eb1804913c Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 1 Jul 2019 14:28:59 +0530 Subject: [PATCH] fix: Make required changes --- erpnext/crm/doctype/utils.py | 14 ++++--- .../exotel_integration.py | 38 ++++++++++--------- erpnext/public/js/call_popup/call_popup.js | 10 ++--- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/erpnext/crm/doctype/utils.py b/erpnext/crm/doctype/utils.py index 5f7a72e4aa..bd8b678d3b 100644 --- a/erpnext/crm/doctype/utils.py +++ b/erpnext/crm/doctype/utils.py @@ -82,12 +82,14 @@ def get_employee_emails_for_popup(communication_medium): now_time = frappe.utils.nowtime() weekday = frappe.utils.get_weekday() - available_employee_groups = frappe.db.sql_list("""SELECT `employee_group` - FROM `tabCommunication Medium Timeslot` - WHERE `day_of_week` = %s - AND `parent` = %s - AND %s BETWEEN `from_time` AND `to_time` - """, (weekday, communication_medium, now_time)) + available_employee_groups = frappe.get_all("Communication Medium Timeslot", filters={ + 'day_of_week': weekday, + 'parent': communication_medium, + 'from_time': ['<=', now_time], + 'to_time': ['>=', 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={ 'parent': ['in', available_employee_groups] diff --git a/erpnext/erpnext_integrations/exotel_integration.py b/erpnext/erpnext_integrations/exotel_integration.py index a42718602a..c04cedce31 100644 --- a/erpnext/erpnext_integrations/exotel_integration.py +++ b/erpnext/erpnext_integrations/exotel_integration.py @@ -6,26 +6,29 @@ import requests # api/method/erpnext.erpnext_integrations.exotel_integration.handle_missed_call @frappe.whitelist(allow_guest=True) -def handle_incoming_call(*args, **kwargs): +def handle_incoming_call(**kwargs): exotel_settings = get_exotel_settings() if not exotel_settings.enabled: return - status = kwargs.get('Status') + call_payload = kwargs + status = call_payload.get('Status') if status == 'free': 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) -def handle_end_call(*args, **kwargs): +def handle_end_call(**kwargs): update_call_log(kwargs, 'Completed') @frappe.whitelist(allow_guest=True) -def handle_missed_call(*args, **kwargs): +def handle_missed_call(**kwargs): update_call_log(kwargs, 'Missed') 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: call_log.status = status call_log.duration = call_payload.get('DialCallDuration') or 0 @@ -34,25 +37,24 @@ def update_call_log(call_payload, status): frappe.db.commit() 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', { 'id': call_payload.get('CallSid'), }, limit=1) if call_log: 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() def get_call_status(call_id): diff --git a/erpnext/public/js/call_popup/call_popup.js b/erpnext/public/js/call_popup/call_popup.js index 17bd74103e..91dfe809a4 100644 --- a/erpnext/public/js/call_popup/call_popup.js +++ b/erpnext/public/js/call_popup/call_popup.js @@ -64,8 +64,8 @@ class CallPopup { } make_caller_info_section() { - const wrapper = this.dialog.fields_dict['caller_info'].$wrapper; - wrapper.append('
Loading...
'); + const wrapper = this.dialog.get_field('caller_info').$wrapper; + wrapper.append(`
${__("Loading...")}
`); frappe.xcall('erpnext.crm.doctype.utils.get_document_with_phone_number', { 'number': this.caller_number }).then(contact_doc => { @@ -88,7 +88,7 @@ class CallPopup { @@ -172,7 +172,7 @@ class CallPopup { 'number': this.caller_number, 'reference_doc': this.contact }).then(data => { - const comm_field = this.dialog.fields_dict["last_communication"]; + const comm_field = this.dialog.get_field('last_communication'); if (data.last_communication) { const comm = data.last_communication; comm_field.set_value(comm.content); @@ -180,7 +180,7 @@ class CallPopup { if (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.$wrapper.append(` ${__('View all issues from {0}', [issue.customer])}