Skip to content

Commit

Permalink
fix: load and show attachments in attachments tab
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Oct 14, 2024
1 parent b40fd4a commit 4eb506e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
13 changes: 8 additions & 5 deletions crm/api/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def get_deal_activities(name):
calls = []
notes = []
tasks = []
attachments = []
creation_text = "created this deal"

if lead:
activities, calls, notes, tasks = get_lead_activities(lead)
activities, calls, notes, tasks, attachments = get_lead_activities(lead)
creation_text = "converted the lead to this deal"

activities.append({
Expand Down Expand Up @@ -134,11 +135,12 @@ def get_deal_activities(name):
calls = calls + get_linked_calls(name)
notes = notes + get_linked_notes(name)
tasks = tasks + get_linked_tasks(name)
attachments = attachments + get_attachments('CRM Deal', name)

activities.sort(key=lambda x: x["creation"], reverse=True)
activities = handle_multiple_versions(activities)

return activities, calls, notes, tasks
return activities, calls, notes, tasks, attachments

def get_lead_activities(name):
get_docinfo('', "CRM Lead", name)
Expand Down Expand Up @@ -248,19 +250,20 @@ def get_lead_activities(name):
calls = get_linked_calls(name)
notes = get_linked_notes(name)
tasks = get_linked_tasks(name)
attachments = get_attachments('CRM Lead', name)

activities.sort(key=lambda x: x["creation"], reverse=True)
activities = handle_multiple_versions(activities)

return activities, calls, notes, tasks
return activities, calls, notes, tasks, attachments

@redis_cache()
def get_attachments(doctype, name):
return frappe.db.get_all(
"File",
filters={"attached_to_doctype": doctype, "attached_to_name": name},
fields=["name", "file_name", "file_url", "file_size", "is_private"],
)
fields=["name", "file_name", "file_url", "file_size", "is_private", "creation", "owner"],
) or []

def handle_multiple_versions(versions):
activities = []
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/components/Activities/Activities.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@
</div>
</div>
</div>
<div v-else-if="title == 'Attachments'">
<div
class="grid grid-cols-1 gap-4 px-3 pb-3 sm:px-10 sm:pb-5 lg:grid-cols-2 xl:grid-cols-3"
>
<div v-for="attachment in activities">
<AttachmentArea :attachment="attachment" />
</div>
</div>
</div>
<div
v-else
v-for="(activity, i) in activities"
Expand Down Expand Up @@ -415,6 +424,7 @@ import CommentArea from '@/components/Activities/CommentArea.vue'
import CallArea from '@/components/Activities/CallArea.vue'
import NoteArea from '@/components/Activities/NoteArea.vue'
import TaskArea from '@/components/Activities/TaskArea.vue'
import AttachmentArea from '@/components/Activities/AttachmentArea.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import ActivityIcon from '@/components/Icons/ActivityIcon.vue'
import Email2Icon from '@/components/Icons/Email2Icon.vue'
Expand Down Expand Up @@ -498,7 +508,7 @@ const all_activities = createResource({
params: { name: doc.value.data.name },
cache: ['activity', doc.value.data.name],
auto: true,
transform: ([versions, calls, notes, tasks]) => {
transform: ([versions, calls, notes, tasks, attachments]) => {
if (calls?.length) {
calls.forEach((doc) => {
doc.show_recording = false
Expand Down Expand Up @@ -533,7 +543,7 @@ const all_activities = createResource({
}
})
}
return { versions, calls, notes, tasks }
return { versions, calls, notes, tasks, attachments }
},
})
Expand Down Expand Up @@ -621,6 +631,9 @@ const activities = computed(() => {
} else if (title.value == 'Notes') {
if (!all_activities.data?.notes) return []
return sortByCreation(all_activities.data.notes)
} else if (title.value == 'Attachments') {
if (!all_activities.data?.attachments) return []
return sortByCreation(all_activities.data.attachments)
}
activities.forEach((activity) => {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/Activities/AttachmentArea.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<div>{{ attachment }}</div>
</template>
<script setup>
const props = defineProps({
attachment: Object,
})
</script>

0 comments on commit 4eb506e

Please sign in to comment.