Merge pull request #74 from shariquerik/load-all-activities
fix: load calls, tasks, notes from get_activities
This commit is contained in:
commit
9a4d967e2d
@ -32,10 +32,13 @@ def get_deal_activities(name):
|
|||||||
lead = doc[2]
|
lead = doc[2]
|
||||||
|
|
||||||
activities = []
|
activities = []
|
||||||
|
calls = []
|
||||||
|
notes = []
|
||||||
|
tasks = []
|
||||||
creation_text = "created this deal"
|
creation_text = "created this deal"
|
||||||
|
|
||||||
if lead:
|
if lead:
|
||||||
activities = get_lead_activities(lead)
|
activities, calls, notes, tasks = get_lead_activities(lead)
|
||||||
creation_text = "converted the lead to this deal"
|
creation_text = "converted the lead to this deal"
|
||||||
|
|
||||||
activities.append({
|
activities.append({
|
||||||
@ -125,10 +128,14 @@ def get_deal_activities(name):
|
|||||||
}
|
}
|
||||||
activities.append(activity)
|
activities.append(activity)
|
||||||
|
|
||||||
|
calls = calls + get_linked_calls(name)
|
||||||
|
notes = notes + get_linked_notes(name)
|
||||||
|
tasks = tasks + get_linked_tasks(name)
|
||||||
|
|
||||||
activities.sort(key=lambda x: x["creation"], reverse=True)
|
activities.sort(key=lambda x: x["creation"], reverse=True)
|
||||||
activities = handle_multiple_versions(activities)
|
activities = handle_multiple_versions(activities)
|
||||||
|
|
||||||
return activities
|
return activities, calls, notes, tasks
|
||||||
|
|
||||||
def get_lead_activities(name):
|
def get_lead_activities(name):
|
||||||
get_docinfo('', "CRM Lead", name)
|
get_docinfo('', "CRM Lead", name)
|
||||||
@ -232,10 +239,14 @@ def get_lead_activities(name):
|
|||||||
}
|
}
|
||||||
activities.append(activity)
|
activities.append(activity)
|
||||||
|
|
||||||
|
calls = get_linked_calls(name)
|
||||||
|
notes = get_linked_notes(name)
|
||||||
|
tasks = get_linked_tasks(name)
|
||||||
|
|
||||||
activities.sort(key=lambda x: x["creation"], reverse=True)
|
activities.sort(key=lambda x: x["creation"], reverse=True)
|
||||||
activities = handle_multiple_versions(activities)
|
activities = handle_multiple_versions(activities)
|
||||||
|
|
||||||
return activities
|
return activities, calls, notes, tasks
|
||||||
|
|
||||||
@redis_cache()
|
@redis_cache()
|
||||||
def get_attachments(name):
|
def get_attachments(name):
|
||||||
@ -276,4 +287,52 @@ def parse_grouped_versions(versions):
|
|||||||
return version
|
return version
|
||||||
other_versions = versions[1:]
|
other_versions = versions[1:]
|
||||||
version["other_versions"] = other_versions
|
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 []
|
||||||
|
|
||||||
|
def get_linked_notes(name):
|
||||||
|
notes = frappe.db.get_all(
|
||||||
|
"CRM Note",
|
||||||
|
filters={"reference_docname": name},
|
||||||
|
fields=['name', 'title', 'content', 'owner', 'modified'],
|
||||||
|
)
|
||||||
|
return notes or []
|
||||||
|
|
||||||
|
def get_linked_tasks(name):
|
||||||
|
tasks = frappe.db.get_all(
|
||||||
|
"CRM Task",
|
||||||
|
filters={"reference_docname": name},
|
||||||
|
fields=[
|
||||||
|
"name",
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"assigned_to",
|
||||||
|
"assigned_to",
|
||||||
|
"due_date",
|
||||||
|
"priority",
|
||||||
|
"status",
|
||||||
|
"modified",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return tasks or []
|
||||||
|
|||||||
@ -717,14 +717,14 @@
|
|||||||
/>
|
/>
|
||||||
<NoteModal
|
<NoteModal
|
||||||
v-model="showNoteModal"
|
v-model="showNoteModal"
|
||||||
v-model:reloadNotes="notes"
|
v-model:reloadNotes="all_activities"
|
||||||
:note="note"
|
:note="note"
|
||||||
:doctype="doctype"
|
:doctype="doctype"
|
||||||
:doc="doc.data?.name"
|
:doc="doc.data?.name"
|
||||||
/>
|
/>
|
||||||
<TaskModal
|
<TaskModal
|
||||||
v-model="showTaskModal"
|
v-model="showTaskModal"
|
||||||
v-model:reloadTasks="tasks"
|
v-model:reloadTasks="all_activities"
|
||||||
:task="task"
|
:task="task"
|
||||||
:doctype="doctype"
|
:doctype="doctype"
|
||||||
:doc="doc.data?.name"
|
:doc="doc.data?.name"
|
||||||
@ -799,119 +799,55 @@ const reload = defineModel('reload')
|
|||||||
|
|
||||||
const reload_email = ref(false)
|
const reload_email = ref(false)
|
||||||
|
|
||||||
const versions = createResource({
|
const all_activities = createResource({
|
||||||
url: 'crm.api.activities.get_activities',
|
url: 'crm.api.activities.get_activities',
|
||||||
params: { name: doc.value.data.name },
|
params: { name: doc.value.data.name },
|
||||||
cache: ['activity', doc.value.data.name],
|
cache: ['activity', doc.value.data.name],
|
||||||
})
|
auto: true,
|
||||||
|
transform: ([versions, calls, notes, tasks]) => {
|
||||||
onMounted(() => {
|
if (calls?.length) {
|
||||||
if (versions.data == null) {
|
calls.forEach((doc) => {
|
||||||
versions.fetch()
|
doc.show_recording = false
|
||||||
}
|
doc.activity_type =
|
||||||
if (calls.data == null) {
|
doc.type === 'Incoming' ? 'incoming_call' : 'outgoing_call'
|
||||||
calls.fetch()
|
doc.duration = secondsToDuration(doc.duration)
|
||||||
}
|
if (doc.type === 'Incoming') {
|
||||||
if (notes.data == null) {
|
doc.caller = {
|
||||||
notes.fetch()
|
label:
|
||||||
}
|
getContact(doc.from)?.full_name ||
|
||||||
if (tasks.data == null) {
|
getLeadContact(doc.from)?.full_name ||
|
||||||
tasks.fetch()
|
'Unknown',
|
||||||
}
|
image:
|
||||||
})
|
getContact(doc.from)?.image || getLeadContact(doc.from)?.image,
|
||||||
|
}
|
||||||
const calls = createListResource({
|
doc.receiver = {
|
||||||
type: 'list',
|
label: getUser(doc.receiver).full_name,
|
||||||
doctype: 'CRM Call Log',
|
image: getUser(doc.receiver).user_image,
|
||||||
cache: ['Call Logs', doc.value.data.name],
|
}
|
||||||
fields: [
|
} else {
|
||||||
'name',
|
doc.caller = {
|
||||||
'caller',
|
label: getUser(doc.caller).full_name,
|
||||||
'receiver',
|
image: getUser(doc.caller).user_image,
|
||||||
'from',
|
}
|
||||||
'to',
|
doc.receiver = {
|
||||||
'duration',
|
label:
|
||||||
'start_time',
|
getContact(doc.to)?.full_name ||
|
||||||
'end_time',
|
getLeadContact(doc.to)?.full_name ||
|
||||||
'status',
|
'Unknown',
|
||||||
'type',
|
image: getContact(doc.to)?.image || getLeadContact(doc.to)?.image,
|
||||||
'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,
|
|
||||||
}
|
}
|
||||||
doc.receiver = {
|
})
|
||||||
label: getUser(doc.receiver).full_name,
|
}
|
||||||
image: getUser(doc.receiver).user_image,
|
return { versions, calls, notes, tasks }
|
||||||
}
|
|
||||||
} 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
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const notes = createListResource({
|
function get_activities() {
|
||||||
type: 'list',
|
if (!all_activities.data?.versions) return []
|
||||||
doctype: 'CRM Note',
|
if (!all_activities.data?.calls.length)
|
||||||
cache: ['Notes', doc.value.data.name],
|
return all_activities.data.versions || []
|
||||||
fields: ['name', 'title', 'content', 'owner', 'modified'],
|
return [...all_activities.data.versions, ...all_activities.data.calls].sort(
|
||||||
filters: { reference_docname: doc.value.data.name },
|
|
||||||
orderBy: 'modified desc',
|
|
||||||
pageLength: 999,
|
|
||||||
})
|
|
||||||
|
|
||||||
const tasks = createListResource({
|
|
||||||
type: 'list',
|
|
||||||
doctype: 'CRM Task',
|
|
||||||
cache: ['Tasks', doc.value.data.name],
|
|
||||||
fields: [
|
|
||||||
'name',
|
|
||||||
'title',
|
|
||||||
'description',
|
|
||||||
'assigned_to',
|
|
||||||
'assigned_to',
|
|
||||||
'due_date',
|
|
||||||
'priority',
|
|
||||||
'status',
|
|
||||||
'modified',
|
|
||||||
],
|
|
||||||
filters: { reference_docname: doc.value.data.name },
|
|
||||||
orderBy: 'modified desc',
|
|
||||||
pageLength: 999,
|
|
||||||
})
|
|
||||||
|
|
||||||
function all_activities() {
|
|
||||||
if (!versions.data) return []
|
|
||||||
if (!calls.data) return versions.data
|
|
||||||
return [...versions.data, ...calls.data].sort(
|
|
||||||
(a, b) => new Date(a.creation) - new Date(b.creation)
|
(a, b) => new Date(a.creation) - new Date(b.creation)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -919,22 +855,25 @@ function all_activities() {
|
|||||||
const activities = computed(() => {
|
const activities = computed(() => {
|
||||||
let activities = []
|
let activities = []
|
||||||
if (props.title == 'Activity') {
|
if (props.title == 'Activity') {
|
||||||
activities = all_activities()
|
activities = get_activities()
|
||||||
} else if (props.title == 'Emails') {
|
} else if (props.title == 'Emails') {
|
||||||
if (!versions.data) return []
|
if (!all_activities.data?.versions) return []
|
||||||
activities = versions.data
|
activities = all_activities.data.versions
|
||||||
.filter((activity) => activity.activity_type === 'communication')
|
.filter((activity) => activity.activity_type === 'communication')
|
||||||
.sort((a, b) => new Date(a.creation) - new Date(b.creation))
|
.sort((a, b) => new Date(a.creation) - new Date(b.creation))
|
||||||
} else if (props.title == 'Calls') {
|
} 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)
|
(a, b) => new Date(a.creation) - new Date(b.creation)
|
||||||
)
|
)
|
||||||
} else if (props.title == 'Tasks') {
|
} else if (props.title == 'Tasks') {
|
||||||
return tasks.data?.sort(
|
if (!all_activities.data?.tasks) return []
|
||||||
|
return all_activities.data.tasks.sort(
|
||||||
(a, b) => new Date(a.creation) - new Date(b.creation)
|
(a, b) => new Date(a.creation) - new Date(b.creation)
|
||||||
)
|
)
|
||||||
} else if (props.title == 'Notes') {
|
} else if (props.title == 'Notes') {
|
||||||
return notes.data?.sort(
|
if (!all_activities.data?.notes) return []
|
||||||
|
return all_activities.data.notes.sort(
|
||||||
(a, b) => new Date(a.creation) - new Date(b.creation)
|
(a, b) => new Date(a.creation) - new Date(b.creation)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1051,7 +990,7 @@ async function deleteNote(name) {
|
|||||||
doctype: 'CRM Note',
|
doctype: 'CRM Note',
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
notes.reload()
|
all_activities.reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tasks
|
// Tasks
|
||||||
@ -1075,7 +1014,7 @@ async function deleteTask(name) {
|
|||||||
doctype: 'CRM Task',
|
doctype: 'CRM Task',
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
tasks.reload()
|
all_activities.reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTaskStatus(status, task) {
|
function updateTaskStatus(status, task) {
|
||||||
@ -1085,7 +1024,7 @@ function updateTaskStatus(status, task) {
|
|||||||
fieldname: 'status',
|
fieldname: 'status',
|
||||||
value: status,
|
value: status,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
tasks.reload()
|
all_activities.reload()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user