Skip to content

Commit

Permalink
fix: added ref doc instead of lead in call log
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Nov 7, 2023
1 parent ce4a45c commit b6060fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
24 changes: 16 additions & 8 deletions crm/fcrm/doctype/crm_call_log/crm_call_log.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"duration",
"medium",
"start_time",
"lead",
"reference_doctype",
"reference_docname",
"column_break_ufnp",
"to",
"type",
Expand Down Expand Up @@ -89,12 +90,6 @@
"fieldtype": "Datetime",
"label": "End Time"
},
{
"fieldname": "lead",
"fieldtype": "Link",
"label": "Lead/Deal",
"options": "CRM Lead"
},
{
"fieldname": "note",
"fieldtype": "Link",
Expand All @@ -114,11 +109,24 @@
"fieldtype": "Link",
"label": "Caller",
"options": "User"
},
{
"default": "CRM Lead",
"fieldname": "reference_doctype",
"fieldtype": "Link",
"label": "Reference Document Type",
"options": "DocType"
},
{
"fieldname": "reference_docname",
"fieldtype": "Dynamic Link",
"label": "Reference Name",
"options": "reference_doctype"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-30 15:39:46.613734",
"modified": "2023-11-07 13:52:40.504747",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Call Log",
Expand Down
26 changes: 17 additions & 9 deletions crm/twilio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ def update_call_log(call_sid, status=None):
call_log.duration = call_details.duration
call_log.start_time = get_datetime_from_timestamp(call_details.start_time)
call_log.end_time = get_datetime_from_timestamp(call_details.end_time)
call_log.lead = get_lead_from_number(call_log)
if call_log.note and call_log.lead:
frappe.db.set_value("CRM Note", call_log.note, "lead", call_log.lead)
call_log.reference_docname, call_log.reference_doctype = get_lead_or_deal_from_number(call_log)
if call_log.note and call_log.reference_docname:
frappe.db.set_value("CRM Note", call_log.note, "reference_doctype", call_log.reference_doctype)
frappe.db.set_value("CRM Note", call_log.note, "reference_docname", call_log.reference_docname)
call_log.flags.ignore_permissions = True
call_log.save()
frappe.db.commit()
Expand Down Expand Up @@ -145,13 +146,20 @@ def add_note_to_call_log(call_sid, note):
frappe.db.set_value("CRM Call Log", call_details.parent_call_sid, "note", note)
frappe.db.commit()

def get_lead_from_number(call):
"""Get lead from the given number.
def get_lead_or_deal_from_number(call):
"""Get lead/deal from the given number.
"""
lead = None
doctype = "CRM Lead"
doc = None
if call.type == 'Outgoing':
lead = frappe.db.get_value("CRM Lead", { "mobile_no": call.get('to') })
doc = frappe.get_cached_value(doctype, { "mobile_no": call.get('to') })
if not doc:
doctype = "CRM Deal"
doc = frappe.get_cached_value(doctype, { "mobile_no": call.get('to') })
else:
lead = frappe.db.get_value("CRM Lead", { "mobile_no": call.get('from') })
doc = frappe.get_cached_value(doctype, { "mobile_no": call.get('from') })
if not doc:
doctype = "CRM Deal"
doc = frappe.get_cached_value(doctype, { "mobile_no": call.get('from') })

return lead
return doc, doctype
2 changes: 1 addition & 1 deletion frontend/src/components/Activities.vue
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ const calls = createListResource({
'creation',
'note',
],
filters: { lead: doc.value.data.name },
filters: { reference_docname: doc.value.data.name },
orderBy: 'creation desc',
pageLength: 999,
auto: true,
Expand Down

0 comments on commit b6060fa

Please sign in to comment.