fix: used get_employees_with_number, strip_number methods

This commit is contained in:
Subin Tom 2022-03-22 16:22:09 +05:30
parent 1ab5b7a811
commit b19305aa83
2 changed files with 17 additions and 17 deletions

View File

@ -4,7 +4,7 @@
"allow_import": 1, "allow_import": 1,
"allow_rename": 1, "allow_rename": 1,
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-03-07 09:04:18", "creation": "2022-02-21 11:54:09.632218",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Setup", "document_type": "Setup",
"editable_grid": 1, "editable_grid": 1,
@ -813,11 +813,12 @@
"idx": 24, "idx": 24,
"image_field": "image", "image_field": "image",
"links": [], "links": [],
"modified": "2021-06-17 11:31:37.730760", "modified": "2022-03-22 13:44:37.088519",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Employee", "name": "Employee",
"name_case": "Title Case", "name_case": "Title Case",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
@ -857,7 +858,9 @@
], ],
"search_fields": "employee_name", "search_fields": "employee_name",
"show_name_in_global_search": 1, "show_name_in_global_search": 1,
"show_title_field_in_link": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"states": [],
"title_field": "employee_name" "title_field": "employee_name"
} }

View File

@ -36,14 +36,11 @@ 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 # Taking the last 10 digits of the number
emp_number_reversed = (self.get("to"))[-1:-11:-1] employee_number = strip_number(self.get('to'))
emp_number = emp_number_reversed[-1::-1] employee = get_employees_with_number(self.get("to"))
employee = frappe.get_all("Employee", filters={
"cell_number": ["like", "%"+emp_number+"%"]
}, fields=["first_name", "middle_name", "last_name", "user_id"])
self.call_received_by = get_employee_name(employee[0]) self.call_received_by = employee[0].get("name")
self.employee_user_id = employee[0].get("user_id") or '' self.employee_user_id = employee[0].get("user_id")
def after_insert(self): def after_insert(self):
self.trigger_call_popup() self.trigger_call_popup()
@ -78,7 +75,8 @@ class CallLog(Document):
def trigger_call_popup(self): def trigger_call_popup(self):
if self.is_incoming_call(): if self.is_incoming_call():
scheduled_employees = get_scheduled_employees_for_popup(self.medium) 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 # check if employees with matched number are scheduled to receive popup
emails = set(scheduled_employees).intersection(employee_emails) emails = set(scheduled_employees).intersection(employee_emails)
@ -115,18 +113,17 @@ def get_employees_with_number(number):
number = strip_number(number) number = strip_number(number)
if not number: return [] if not number: return []
employee_emails = frappe.cache().hget('employees_with_number', number) employee_doc_name_and_emails = frappe.cache().hget('employees_with_number', number)
if employee_emails: return employee_emails if employee_doc_name_and_emails: return employee_doc_name_and_emails
employees = frappe.get_all('Employee', filters={ employee_doc_name_and_emails = frappe.get_all('Employee', filters={
'cell_number': ['like', '%{}%'.format(number)], 'cell_number': ['like', '%{}%'.format(number)],
'user_id': ['!=', ''] '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_doc_name_and_emails)
frappe.cache().hset('employees_with_number', number, employee_emails)
return employee_emails return employee_doc_name_and_emails
def link_existing_conversations(doc, state): def link_existing_conversations(doc, state):
""" """