fix: Update received_by if "to" is changed
This commit is contained in:
parent
cef28df8db
commit
ff41b8da4e
@ -34,11 +34,7 @@ class CallLog(Document):
|
|||||||
|
|
||||||
# Add Employee Name
|
# Add Employee Name
|
||||||
if self.is_incoming_call():
|
if self.is_incoming_call():
|
||||||
# Taking the last 10 digits of the number
|
self.update_received_by()
|
||||||
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")
|
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
self.trigger_call_popup()
|
self.trigger_call_popup()
|
||||||
@ -57,6 +53,9 @@ class CallLog(Document):
|
|||||||
if not doc_before_save:
|
if not doc_before_save:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.is_incoming_call() and self.has_value_changed("to"):
|
||||||
|
self.update_received_by()
|
||||||
|
|
||||||
if _is_call_missed(doc_before_save, self):
|
if _is_call_missed(doc_before_save, self):
|
||||||
frappe.publish_realtime("call_{id}_missed".format(id=self.id), self)
|
frappe.publish_realtime("call_{id}_missed".format(id=self.id), self)
|
||||||
self.trigger_call_popup()
|
self.trigger_call_popup()
|
||||||
@ -94,6 +93,11 @@ class CallLog(Document):
|
|||||||
for email in emails:
|
for email in emails:
|
||||||
frappe.publish_realtime("show_call_popup", self, user=email)
|
frappe.publish_realtime("show_call_popup", self, user=email)
|
||||||
|
|
||||||
|
def update_received_by(self):
|
||||||
|
if employees := get_employees_with_number(self.get("to")):
|
||||||
|
self.call_received_by = employees[0].get("name")
|
||||||
|
self.employee_user_id = employees[0].get("user_id")
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def add_call_summary_and_call_type(call_log, summary, call_type):
|
def add_call_summary_and_call_type(call_log, summary, call_type):
|
||||||
@ -114,7 +118,7 @@ def get_employees_with_number(number):
|
|||||||
|
|
||||||
employee_doc_name_and_emails = frappe.get_all(
|
employee_doc_name_and_emails = frappe.get_all(
|
||||||
"Employee",
|
"Employee",
|
||||||
filters={"cell_number": ["like", "%{}%".format(number)], "user_id": ["!=", ""]},
|
filters={"cell_number": ["like", f"%{number}%"], "user_id": ["!=", ""]},
|
||||||
fields=["name", "user_id"],
|
fields=["name", "user_id"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ class TestExotel(FrappeAPITestCase):
|
|||||||
cls.test_employee_name = make_employee(
|
cls.test_employee_name = make_employee(
|
||||||
user="test_employee_exotel@company.com", cell_number="9999999999"
|
user="test_employee_exotel@company.com", cell_number="9999999999"
|
||||||
)
|
)
|
||||||
|
frappe.db.set_value("Exotel Settings", "Exotel Settings", "enabled", 1)
|
||||||
phones = [{"phone": "+91 9999999991", "is_primary_phone": 0, "is_primary_mobile_no": 1}]
|
phones = [{"phone": "+91 9999999991", "is_primary_phone": 0, "is_primary_mobile_no": 1}]
|
||||||
create_contact(name="Test Contact", salutation="Mr", phones=phones)
|
create_contact(name="Test Contact", salutation="Mr", phones=phones)
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
Loading…
Reference in New Issue
Block a user