fix: Update received_by if "to" is changed
diff --git a/erpnext/telephony/doctype/call_log/call_log.py b/erpnext/telephony/doctype/call_log/call_log.py
index 2092ec2..7725e71 100644
--- a/erpnext/telephony/doctype/call_log/call_log.py
+++ b/erpnext/telephony/doctype/call_log/call_log.py
@@ -34,11 +34,7 @@
# Add Employee Name
if self.is_incoming_call():
- # Taking the last 10 digits of the number
- 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")
+ self.update_received_by()
def after_insert(self):
self.trigger_call_popup()
@@ -57,6 +53,9 @@
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()
@@ -94,6 +93,11 @@
for email in emails:
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()
def add_call_summary_and_call_type(call_log, summary, call_type):
@@ -114,7 +118,7 @@
employee_doc_name_and_emails = frappe.get_all(
"Employee",
- filters={"cell_number": ["like", "%{}%".format(number)], "user_id": ["!=", ""]},
+ filters={"cell_number": ["like", f"%{number}%"], "user_id": ["!=", ""]},
fields=["name", "user_id"],
)
diff --git a/erpnext/tests/test_exotel.py b/erpnext/tests/test_exotel.py
index bb916a8..76bbb3e 100644
--- a/erpnext/tests/test_exotel.py
+++ b/erpnext/tests/test_exotel.py
@@ -12,6 +12,7 @@
cls.test_employee_name = make_employee(
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}]
create_contact(name="Test Contact", salutation="Mr", phones=phones)
frappe.db.commit()