1
0
forked from test/crm

fix: load calls from get_activities

This commit is contained in:
Shariq Ansari 2024-02-18 16:55:45 +05:30
parent 4920027e85
commit 3ba549422e
2 changed files with 78 additions and 84 deletions

View File

@ -32,10 +32,11 @@ def get_deal_activities(name):
lead = doc[2]
activities = []
calls = []
creation_text = "created this deal"
if lead:
activities = get_lead_activities(lead)
activities, calls = get_lead_activities(lead)
creation_text = "converted the lead to this deal"
activities.append({
@ -125,10 +126,12 @@ def get_deal_activities(name):
}
activities.append(activity)
calls = calls + get_linked_calls(name)
activities.sort(key=lambda x: x["creation"], reverse=True)
activities = handle_multiple_versions(activities)
return activities
return activities, calls
def get_lead_activities(name):
get_docinfo('', "CRM Lead", name)
@ -232,10 +235,12 @@ def get_lead_activities(name):
}
activities.append(activity)
calls = get_linked_calls(name)
activities.sort(key=lambda x: x["creation"], reverse=True)
activities = handle_multiple_versions(activities)
return activities
return activities, calls
@redis_cache()
def get_attachments(name):
@ -276,4 +281,26 @@ def parse_grouped_versions(versions):
return version
other_versions = versions[1:]
version["other_versions"] = other_versions
return version
return version
def get_linked_calls(name):
calls = frappe.db.get_all(
"CRM Call Log",
filters={"reference_docname": name},
fields=[
"name",
"caller",
"receiver",
"from",
"to",
"duration",
"start_time",
"end_time",
"status",
"type",
"recording_url",
"creation",
"note",
],
)
return calls or []

View File

@ -799,82 +799,47 @@ const reload = defineModel('reload')
const reload_email = ref(false)
const versions = createResource({
const all_activities = createResource({
url: 'crm.api.activities.get_activities',
params: { name: doc.value.data.name },
cache: ['activity', doc.value.data.name],
})
onMounted(() => {
if (versions.data == null) {
versions.fetch()
}
if (calls.data == null) {
calls.fetch()
}
if (notes.data == null) {
notes.fetch()
}
if (tasks.data == null) {
tasks.fetch()
}
})
const calls = createListResource({
type: 'list',
doctype: 'CRM Call Log',
cache: ['Call Logs', doc.value.data.name],
fields: [
'name',
'caller',
'receiver',
'from',
'to',
'duration',
'start_time',
'end_time',
'status',
'type',
'recording_url',
'creation',
'note',
],
filters: { reference_docname: doc.value.data.name },
orderBy: 'creation desc',
pageLength: 999,
transform: (docs) => {
docs.forEach((doc) => {
doc.show_recording = false
doc.activity_type =
doc.type === 'Incoming' ? 'incoming_call' : 'outgoing_call'
doc.duration = secondsToDuration(doc.duration)
if (doc.type === 'Incoming') {
doc.caller = {
label:
getContact(doc.from)?.full_name ||
getLeadContact(doc.from)?.full_name ||
'Unknown',
image: getContact(doc.from)?.image || getLeadContact(doc.from)?.image,
auto: true,
transform: ([versions, calls]) => {
if (calls?.length) {
calls.forEach((doc) => {
doc.show_recording = false
doc.activity_type =
doc.type === 'Incoming' ? 'incoming_call' : 'outgoing_call'
doc.duration = secondsToDuration(doc.duration)
if (doc.type === 'Incoming') {
doc.caller = {
label:
getContact(doc.from)?.full_name ||
getLeadContact(doc.from)?.full_name ||
'Unknown',
image:
getContact(doc.from)?.image || getLeadContact(doc.from)?.image,
}
doc.receiver = {
label: getUser(doc.receiver).full_name,
image: getUser(doc.receiver).user_image,
}
} else {
doc.caller = {
label: getUser(doc.caller).full_name,
image: getUser(doc.caller).user_image,
}
doc.receiver = {
label:
getContact(doc.to)?.full_name ||
getLeadContact(doc.to)?.full_name ||
'Unknown',
image: getContact(doc.to)?.image || getLeadContact(doc.to)?.image,
}
}
doc.receiver = {
label: getUser(doc.receiver).full_name,
image: getUser(doc.receiver).user_image,
}
} else {
doc.caller = {
label: getUser(doc.caller).full_name,
image: getUser(doc.caller).user_image,
}
doc.receiver = {
label:
getContact(doc.to)?.full_name ||
getLeadContact(doc.to)?.full_name ||
'Unknown',
image: getContact(doc.to)?.image || getLeadContact(doc.to)?.image,
}
}
})
return docs
})
}
return { versions, calls }
},
})
@ -908,10 +873,11 @@ const tasks = createListResource({
pageLength: 999,
})
function all_activities() {
if (!versions.data) return []
if (!calls.data) return versions.data
return [...versions.data, ...calls.data].sort(
function get_activities() {
if (!all_activities.data?.versions) return []
if (!all_activities.data?.calls.length)
return all_activities.data.versions || []
return [...all_activities.data.versions, ...all_activities.data.calls].sort(
(a, b) => new Date(a.creation) - new Date(b.creation)
)
}
@ -919,14 +885,15 @@ function all_activities() {
const activities = computed(() => {
let activities = []
if (props.title == 'Activity') {
activities = all_activities()
activities = get_activities()
} else if (props.title == 'Emails') {
if (!versions.data) return []
activities = versions.data
if (!all_activities.data?.versions) return []
activities = all_activities.data.versions
.filter((activity) => activity.activity_type === 'communication')
.sort((a, b) => new Date(a.creation) - new Date(b.creation))
} else if (props.title == 'Calls') {
return calls.data?.sort(
if (!all_activities.data?.calls) return []
return all_activities.data.calls.sort(
(a, b) => new Date(a.creation) - new Date(b.creation)
)
} else if (props.title == 'Tasks') {