Skip to content

Commit

Permalink
Merge pull request #31903 from frappe/exotel_fixes_v13
Browse files Browse the repository at this point in the history
  • Loading branch information
surajshetty3416 authored Aug 22, 2022
2 parents 6bc6681 + 23a4412 commit d46ce05
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def test_make_supplier_quotation_with_special_characters(self):
)
sq.submit()

frappe.form_dict = frappe.local("form_dict")
frappe.form_dict.name = rfq.name

self.assertEqual(check_supplier_has_docname_access(supplier_wt_appos[0].get("supplier")), True)
Expand Down
30 changes: 19 additions & 11 deletions erpnext/erpnext_integrations/exotel_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,26 @@ def handle_end_call(**kwargs):

@frappe.whitelist(allow_guest=True)
def handle_missed_call(**kwargs):
update_call_log(kwargs, "Missed")
status = ""
call_type = kwargs.get("CallType")
dial_call_status = kwargs.get("DialCallStatus")

if call_type == "incomplete" and dial_call_status == "no-answer":
status = "No Answer"
elif call_type == "client-hangup" and dial_call_status == "canceled":
status = "Canceled"
elif call_type == "incomplete" and dial_call_status == "failed":
status = "Failed"

update_call_log(kwargs, status)


def update_call_log(call_payload, status="Ringing", call_log=None):
call_log = call_log or get_call_log(call_payload)

# for a new sid, call_log and get_call_log will be empty so create a new log
if not call_log:
call_log = create_call_log(call_payload)
if call_log:
call_log.status = status
call_log.to = call_payload.get("DialWhomNumber")
Expand All @@ -53,16 +68,9 @@ def update_call_log(call_payload, status="Ringing", call_log=None):


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)
call_log_id = call_payload.get("CallSid")
if frappe.db.exists("Call Log", call_log_id):
return frappe.get_doc("Call Log", call_log_id)


def create_call_log(call_payload):
Expand Down
5 changes: 3 additions & 2 deletions erpnext/hr/doctype/employee/employee.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"allow_import": 1,
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2013-03-07 09:04:18",
"creation": "2022-02-21 11:54:09.632218",
"doctype": "DocType",
"document_type": "Setup",
"editable_grid": 1,
Expand Down Expand Up @@ -813,11 +813,12 @@
"idx": 24,
"image_field": "image",
"links": [],
"modified": "2022-07-18 20:03:43.188705",
"modified": "2022-08-20 13:44:37.088519",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee",
"name_case": "Title Case",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator",
"permissions": [
{
Expand Down
12 changes: 11 additions & 1 deletion erpnext/public/js/call_popup/call_popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ class CallPopup {
}, {
'fieldtype': 'Section Break',
'hide_border': 1,
}, {
'fieldname': 'call_type',
'label': 'Call Type',
'fieldtype': 'Link',
'options': 'Telephony Call Type',
}, {
'fieldtype': 'Section Break',
'hide_border': 1,
}, {
'fieldtype': 'Small Text',
'label': __('Call Summary'),
Expand All @@ -149,10 +157,12 @@ class CallPopup {
'label': __('Save'),
'click': () => {
const call_summary = this.call_details.get_value('call_summary');
const call_type = this.call_details.get_value('call_type');
if (!call_summary) return;
frappe.xcall('erpnext.telephony.doctype.call_log.call_log.add_call_summary', {
frappe.xcall('erpnext.telephony.doctype.call_log.call_log.add_call_summary_and_call_type', {
'call_log': this.call_log.name,
'summary': call_summary,
'call_type': call_type,
}).then(() => {
this.close_modal();
frappe.show_alert({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_add_node(self):
)
).insert()

frappe.form_dict = dict(
frappe.local.form_dict = frappe._dict(
doctype="Quality Procedure",
quality_procedure_name="Test Child 1",
parent_quality_procedure=procedure.name,
Expand Down
30 changes: 27 additions & 3 deletions erpnext/telephony/doctype/call_log/call_log.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"actions": [],
"autoname": "field:id",
"creation": "2019-06-05 12:07:02.634534",
"creation": "2022-02-21 11:54:58.414784",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"call_details_section",
"id",
"from",
"to",
"call_received_by",
"employee_user_id",
"medium",
"start_time",
"end_time",
Expand All @@ -20,6 +22,7 @@
"recording_url",
"recording_html",
"section_break_11",
"type_of_call",
"summary",
"section_break_19",
"links"
Expand Down Expand Up @@ -103,7 +106,8 @@
},
{
"fieldname": "summary",
"fieldtype": "Small Text"
"fieldtype": "Small Text",
"label": "Summary"
},
{
"fieldname": "section_break_11",
Expand Down Expand Up @@ -134,15 +138,34 @@
"fieldname": "call_details_section",
"fieldtype": "Section Break",
"label": "Call Details"
},
{
"fieldname": "employee_user_id",
"fieldtype": "Data",
"hidden": 1,
"label": "Employee User Id"
},
{
"fieldname": "type_of_call",
"fieldtype": "Data",
"label": "Type Of Call"
},
{
"depends_on": "to",
"fieldname": "call_received_by",
"fieldtype": "Data",
"label": "Call Received By",
"read_only": 1
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-02-08 14:23:28.744844",
"modified": "2022-02-25 14:37:48.575230",
"modified_by": "Administrator",
"module": "Telephony",
"name": "Call Log",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
Expand All @@ -164,6 +187,7 @@
],
"sort_field": "creation",
"sort_order": "DESC",
"states": [],
"title_field": "from",
"track_changes": 1,
"track_views": 1
Expand Down
35 changes: 25 additions & 10 deletions erpnext/telephony/doctype/call_log/call_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def before_insert(self):
if lead:
self.add_link(link_type="Lead", link_name=lead)

# Add Employee Name
if self.is_incoming_call():
self.update_received_by()

def after_insert(self):
self.trigger_call_popup()

Expand All @@ -49,6 +53,9 @@ def _is_call_ended(doc_before_save, doc_after_save):
if not doc_before_save:
return

if self.is_incoming_call() and self.has_value_changed("to"):
self.update_received_by()

if _is_call_missed(doc_before_save, self):
frappe.publish_realtime("call_{id}_missed".format(id=self.id), self)
self.trigger_call_popup()
Expand All @@ -65,7 +72,8 @@ def add_link(self, link_type, link_name):
def trigger_call_popup(self):
if self.is_incoming_call():
scheduled_employees = get_scheduled_employees_for_popup(self.medium)
employee_emails = get_employees_with_number(self.to)
employees = get_employees_with_number(self.to)
employee_emails = [employee.get("user_id") for employee in employees]

# check if employees with matched number are scheduled to receive popup
emails = set(scheduled_employees).intersection(employee_emails)
Expand All @@ -85,10 +93,18 @@ def trigger_call_popup(self):
for email in emails:
frappe.publish_realtime("show_call_popup", self, user=email)

def update_received_by(self):
employees = get_employees_with_number(self.get("to"))
if employees:
self.call_received_by = employees[0].get("name")
self.employee_user_id = employees[0].get("user_id")


@frappe.whitelist()
def add_call_summary(call_log, summary):
def add_call_summary_and_call_type(call_log, summary, call_type):
doc = frappe.get_doc("Call Log", call_log)
doc.type_of_call = call_type
doc.save()
doc.add_comment("Comment", frappe.bold(_("Call Summary")) + "<br><br>" + summary)


Expand All @@ -97,20 +113,19 @@ def get_employees_with_number(number):
if not number:
return []

employee_emails = frappe.cache().hget("employees_with_number", number)
if employee_emails:
return employee_emails
employee_doc_name_and_emails = frappe.cache().hget("employees_with_number", number)
if employee_doc_name_and_emails:
return employee_doc_name_and_emails

employees = frappe.get_all(
employee_doc_name_and_emails = frappe.get_all(
"Employee",
filters={"cell_number": ["like", "%{}%".format(number)], "user_id": ["!=", ""]},
fields=["user_id"],
fields=["name", "user_id"],
)

employee_emails = [employee.user_id for employee in employees]
frappe.cache().hset("employees_with_number", number, employee_emails)
frappe.cache().hset("employees_with_number", number, employee_doc_name_and_emails)

return employee_emails
return employee_doc_name_and_emails


def link_existing_conversations(doc, state):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

frappe.ui.form.on('Telephony Call Type', {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:call_type",
"creation": "2022-02-25 16:13:37.321312",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"call_type",
"amended_from"
],
"fields": [
{
"fieldname": "call_type",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Call Type",
"reqd": 1,
"unique": 1
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Telephony Call Type",
"print_hide": 1,
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-02-25 16:14:07.087461",
"modified_by": "Administrator",
"module": "Telephony",
"name": "Telephony Call Type",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class TelephonyCallType(Document):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

# import frappe
import unittest


class TestTelephonyCallType(unittest.TestCase):
pass
Loading

0 comments on commit d46ce05

Please sign in to comment.