fix: Change call log fieldname and some cleanups

This commit is contained in:
Suraj Shetty
2019-06-07 10:22:50 +05:30
parent 97780613ad
commit c8c17422f7
4 changed files with 69 additions and 71 deletions

View File

@@ -1,71 +1,71 @@
{ {
"autoname": "field:call_id", "autoname": "field:id",
"creation": "2019-06-05 12:07:02.634534", "creation": "2019-06-05 12:07:02.634534",
"doctype": "DocType", "doctype": "DocType",
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"call_id", "id",
"call_from", "from",
"column_break_3", "column_break_3",
"received_by", "to",
"section_break_5", "section_break_5",
"call_status", "status",
"call_duration", "duration",
"call_summary" "summary"
], ],
"fields": [ "fields": [
{
"fieldname": "call_id",
"fieldtype": "Data",
"label": "Call ID",
"read_only": 1,
"unique": 1
},
{
"fieldname": "call_from",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Call From",
"read_only": 1
},
{ {
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{
"fieldname": "received_by",
"fieldtype": "Data",
"label": "Received By",
"read_only": 1
},
{ {
"fieldname": "section_break_5", "fieldname": "section_break_5",
"fieldtype": "Section Break" "fieldtype": "Section Break"
}, },
{ {
"fieldname": "call_status", "fieldname": "id",
"fieldtype": "Data",
"label": "ID",
"read_only": 1,
"unique": 1
},
{
"fieldname": "from",
"fieldtype": "Data",
"in_list_view": 1,
"label": "From",
"read_only": 1
},
{
"fieldname": "to",
"fieldtype": "Data",
"label": "To",
"read_only": 1
},
{
"fieldname": "status",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1, "in_list_view": 1,
"label": "Call Status", "label": "Status",
"options": "Ringing\nIn Progress\nCompleted\nMissed", "options": "Ringing\nIn Progress\nCompleted\nMissed",
"read_only": 1 "read_only": 1
}, },
{ {
"description": "Call Duration in seconds", "description": "Call Duration in seconds",
"fieldname": "call_duration", "fieldname": "duration",
"fieldtype": "Int", "fieldtype": "Int",
"in_list_view": 1, "in_list_view": 1,
"label": "Call Duration", "label": "Duration",
"read_only": 1 "read_only": 1
}, },
{ {
"fieldname": "call_summary", "fieldname": "summary",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Call Summary", "label": "Summary",
"read_only": 1 "read_only": 1
} }
], ],
"modified": "2019-06-06 07:41:26.208109", "modified": "2019-06-07 09:49:07.623814",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Communication", "module": "Communication",
"name": "Call Log", "name": "Call Log",
@@ -86,6 +86,6 @@
], ],
"sort_field": "modified", "sort_field": "modified",
"sort_order": "ASC", "sort_order": "ASC",
"title_field": "call_from", "title_field": "from",
"track_changes": 1 "track_changes": 1
} }

View File

@@ -78,17 +78,17 @@ def add_call_summary(docname, summary):
call_log.call_summary += '<br>' + content call_log.call_summary += '<br>' + content
call_log.save(ignore_permissions=True) call_log.save(ignore_permissions=True)
def get_employee_emails_for_popup(): def get_employee_emails_for_popup(communication_medium):
employee_emails = [] employee_emails = []
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("""SELECT `parent`, `employee_group` available_employee_groups = frappe.db.sql("""SELECT `parent`, `employee_group`
FROM `tabCommunication Medium Timeslot` FROM `tabCommunication Medium Timeslot`
WHERE `day_of_week` = %s AND WHERE `day_of_week` = %s
%s BETWEEN `from_time` AND `to_time` AND `parent` = %s
""", (weekday, now_time), as_dict=1) AND %s BETWEEN `from_time` AND `to_time`
""", (weekday, communication_medium, now_time), as_dict=1)
for group in available_employee_groups: for group in available_employee_groups:
employee_emails += [e.user_id for e in frappe.get_doc('Employee Group', group.employee_group).employee_list] employee_emails += [e.user_id for e in frappe.get_doc('Employee Group', group.employee_group).employee_list]

View File

@@ -3,6 +3,8 @@ from erpnext.crm.doctype.utils import get_document_with_phone_number, get_employ
import requests import requests
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call # api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_end_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(*args, **kwargs):
@@ -18,41 +20,43 @@ def handle_incoming_call(*args, **kwargs):
call_log = get_call_log(kwargs) call_log = get_call_log(kwargs)
employee_emails = get_employee_emails_for_popup() employee_emails = get_employee_emails_for_popup(kwargs.get('To'))
for email in employee_emails: for email in employee_emails:
frappe.publish_realtime('show_call_popup', call_log, user=email) frappe.publish_realtime('show_call_popup', call_log, user=email)
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def handle_end_call(*args, **kwargs): def handle_end_call(*args, **kwargs):
update_call_log(kwargs, 'Completed') call_log = update_call_log(kwargs, 'Completed')
frappe.publish_realtime('call_disconnected', kwargs.get('CallSid')) frappe.publish_realtime('call_disconnected', call_log)
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def handle_missed_call(*args, **kwargs): def handle_missed_call(*args, **kwargs):
update_call_log(kwargs, 'Missed') call_log = update_call_log(kwargs, 'Missed')
frappe.publish_realtime('call_disconnected', kwargs.get('CallSid')) frappe.publish_realtime('call_disconnected', call_log)
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, False)
if call_log: if call_log:
call_log.call_status = status call_log.status = status
call_log.call_duration = call_payload.get('DialCallDuration') or 0 call_log.duration = call_payload.get('DialCallDuration') or 0
call_log.save(ignore_permissions=True) call_log.save(ignore_permissions=True)
frappe.db.commit() frappe.db.commit()
return call_log
def get_call_log(call_payload, create_new_if_not_found=True): def get_call_log(call_payload, create_new_if_not_found=True):
call_log = frappe.get_all('Call Log', { call_log = frappe.get_all('Call Log', {
'call_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: elif create_new_if_not_found:
call_log = frappe.new_doc('Call Log') call_log = frappe.new_doc('Call Log')
call_log.call_id = call_payload.get('CallSid') call_log.id = call_payload.get('CallSid')
call_log.call_from = call_payload.get('CallFrom') call_log.to = call_payload.get('To')
call_log.status = 'Ringing' call_log.status = 'Ringing'
setattr(call_log, 'from', call_payload.get('CallFrom'))
call_log.save(ignore_permissions=True) call_log.save(ignore_permissions=True)
frappe.db.commit() frappe.db.commit()
return call_log return call_log

View File

@@ -1,6 +1,6 @@
class CallPopup { class CallPopup {
constructor(call_log) { constructor(call_log) {
this.caller_number = call_log.call_from; this.caller_number = call_log.from;
this.call_log = call_log; this.call_log = call_log;
this.make(); this.make();
} }
@@ -20,17 +20,11 @@ class CallPopup {
'label': "Last Communication", 'label': "Last Communication",
'fieldname': 'last_communication', 'fieldname': 'last_communication',
'read_only': true 'read_only': true
}, {
'fieldname': 'last_communication_link',
'fieldtype': 'HTML',
}, { }, {
'fieldtype': 'Small Text', 'fieldtype': 'Small Text',
'label': "Last Issue", 'label': "Last Issue",
'fieldname': 'last_issue', 'fieldname': 'last_issue',
'read_only': true 'read_only': true
}, {
'fieldname': 'last_issue_link',
'fieldtype': 'HTML',
}, { }, {
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
}, { }, {
@@ -44,26 +38,23 @@ class CallPopup {
const values = this.dialog.get_values(); const values = this.dialog.get_values();
if (!values.call_summary) return if (!values.call_summary) return
frappe.xcall('erpnext.crm.doctype.utils.add_call_summary', { frappe.xcall('erpnext.crm.doctype.utils.add_call_summary', {
'docname': this.call_log.call_id, 'docname': this.call_log.id,
'summary': values.call_summary, 'summary': values.call_summary,
}).then(() => { }).then(() => {
this.dialog.set_value('call_summary', ''); this.dialog.set_value('call_summary', '');
}); });
} }
}], }],
on_minimize_toggle: () => {
this.set_call_status();
}
}); });
this.set_call_status(); this.set_call_status();
this.make_caller_info_section(); this.make_caller_info_section();
this.dialog.get_close_btn().show(); this.dialog.get_close_btn().show();
this.dialog.$body.addClass('call-popup'); this.dialog.$body.addClass('call-popup');
this.dialog.set_secondary_action(() => { this.dialog.set_secondary_action(() => {
clearInterval(this.updater);
delete erpnext.call_popup; delete erpnext.call_popup;
this.dialog.hide(); this.dialog.hide();
}); });
frappe.utils.play_sound("incoming_call");
this.dialog.show(); this.dialog.show();
} }
@@ -112,7 +103,7 @@ class CallPopup {
set_call_status(call_status) { set_call_status(call_status) {
let title = ''; let title = '';
call_status = call_status || this.call_log.call_status; call_status = call_status || this.call_log.status;
if (['Ringing'].includes(call_status) || !call_status) { if (['Ringing'].includes(call_status) || !call_status) {
title = __('Incoming call from {0}', title = __('Incoming call from {0}',
[this.contact ? `${this.contact.first_name || ''} ${this.contact.last_name || ''}` : this.caller_number]); [this.contact ? `${this.contact.first_name || ''} ${this.contact.last_name || ''}` : this.caller_number]);
@@ -120,7 +111,7 @@ class CallPopup {
} else if (call_status === 'In Progress') { } else if (call_status === 'In Progress') {
title = __('Call Connected'); title = __('Call Connected');
this.set_indicator('yellow'); this.set_indicator('yellow');
} else if (call_status === 'missed') { } else if (call_status === 'Missed') {
this.set_indicator('red'); this.set_indicator('red');
title = __('Call Missed'); title = __('Call Missed');
} else if (['Completed', 'Disconnected'].includes(call_status)) { } else if (['Completed', 'Disconnected'].includes(call_status)) {
@@ -137,9 +128,10 @@ class CallPopup {
this.call_log = call_log; this.call_log = call_log;
this.set_call_status(); this.set_call_status();
} }
disconnect_call() {
this.set_call_status('Disconnected'); call_disconnected(call_log) {
clearInterval(this.updater); frappe.utils.play_sound("call_disconnect");
this.update_call_log(call_log);
} }
make_last_interaction_section() { make_last_interaction_section() {
@@ -147,12 +139,14 @@ 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"];
if (data.last_communication) { if (data.last_communication) {
const comm = data.last_communication; const comm = data.last_communication;
// this.dialog.set_df_property('last_interaction', 'hidden', false); // this.dialog.set_df_property('last_interaction', 'hidden', false);
const comm_field = this.dialog.fields_dict["last_communication"];
comm_field.set_value(comm.content); comm_field.set_value(comm.content);
comm_field.$wrapper.append(frappe.utils.get_form_link('Communication', comm.name)); comm_field.$wrapper.append(frappe.utils.get_form_link('Communication', comm.name));
} else {
comm_field.$wrapper.hide();
} }
if (data.last_issue) { if (data.last_issue) {
@@ -176,9 +170,9 @@ $(document).on('app_ready', function () {
erpnext.call_popup.dialog.show(); erpnext.call_popup.dialog.show();
} }
}); });
frappe.realtime.on('call_disconnected', id => { frappe.realtime.on('call_disconnected', call_log => {
if (erpnext.call_popup && erpnext.call_popup.call_log.call_id === id) { if (erpnext.call_popup && erpnext.call_popup.call_log.id === call_log.id) {
erpnext.call_popup.disconnect_call(); erpnext.call_popup.call_disconnected(call_log);
} }
}); });
}); });