fix: get lead, deal, note & task details if linked

This commit is contained in:
Shariq Ansari 2025-01-18 18:39:00 +05:30
parent 7dd53d88e5
commit 50508cc6b0
3 changed files with 46 additions and 41 deletions

View File

@ -185,7 +185,8 @@ def get_quick_filters(doctype: str):
if field.fieldtype == "Select" and options and isinstance(options, str): if field.fieldtype == "Select" and options and isinstance(options, str):
options = options.split("\n") options = options.split("\n")
options = [{"label": option, "value": option} for option in options] options = [{"label": option, "value": option} for option in options]
options.insert(0, {"label": "", "value": ""}) if not any([not option.get("value") for option in options]):
options.insert(0, {"label": "", "value": ""})
quick_filters.append( quick_filters.append(
{ {
"label": _(field.label), "label": _(field.label),

View File

@ -155,7 +155,38 @@ def get_call_log(name):
"creation", "creation",
], ],
).as_dict() ).as_dict()
return parse_call_log(call)
call = parse_call_log(call)
notes = []
tasks = []
if call.get("note"):
note = frappe.get_cached_doc("FCRM Note", call.get("note")).as_dict()
notes.append(note)
if call.get("reference_doctype") and call.get("reference_docname"):
if call.get("reference_doctype") == "CRM Lead":
call["_lead"] = call.get("reference_docname")
elif call.get("reference_doctype") == "CRM Deal":
call["_deal"] = call.get("reference_docname")
if call.get("links"):
for link in call.get("links"):
if link.get("link_doctype") == "CRM Task":
task = frappe.get_cached_doc("CRM Task", link.get("link_name")).as_dict()
tasks.append(task)
elif link.get("link_doctype") == "FCRM Note":
note = frappe.get_cached_doc("FCRM Note", link.get("link_name")).as_dict()
notes.append(note)
elif link.get("link_doctype") == "CRM Lead":
call["_lead"] = link.get("link_name")
elif link.get("link_doctype") == "CRM Deal":
call["_deal"] = link.get("link_name")
call["_tasks"] = tasks
call["_notes"] = notes
return call
@frappe.whitelist() @frappe.whitelist()

View File

@ -83,13 +83,7 @@
</div> </div>
</div> </div>
</template> </template>
<template <template v-if="!callLog.data?._lead && !callLog.data?._deal" #actions>
v-if="
callLog.data?.type.label == 'Incoming' &&
!callLog.data?.reference_docname
"
#actions
>
<Button <Button
class="w-full" class="w-full"
variant="solid" variant="solid"
@ -98,7 +92,7 @@
/> />
</template> </template>
</Dialog> </Dialog>
<NoteModal v-model="showNoteModal" :note="callNoteDoc?.doc" /> <NoteModal v-model="showNoteModal" :note="callNoteDoc" />
</template> </template>
<script setup> <script setup>
@ -112,14 +106,7 @@ import NoteIcon from '@/components/Icons/NoteIcon.vue'
import CheckCircleIcon from '@/components/Icons/CheckCircleIcon.vue' import CheckCircleIcon from '@/components/Icons/CheckCircleIcon.vue'
import NoteModal from '@/components/Modals/NoteModal.vue' import NoteModal from '@/components/Modals/NoteModal.vue'
import FadedScrollableDiv from '@/components/FadedScrollableDiv.vue' import FadedScrollableDiv from '@/components/FadedScrollableDiv.vue'
import { import { FeatherIcon, Avatar, Tooltip, call, createResource } from 'frappe-ui'
FeatherIcon,
Avatar,
Tooltip,
createDocumentResource,
call,
createResource,
} from 'frappe-ui'
import { getCallLogDetail } from '@/utils/callLog' import { getCallLogDetail } from '@/utils/callLog'
import { ref, computed, h, watch } from 'vue' import { ref, computed, h, watch } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
@ -157,27 +144,23 @@ const detailFields = computed(() => {
}, },
}, },
{ {
icon: icon: callLog.value.data._lead ? LeadsIcon : Dealsicon,
callLog.value.data.reference_doctype == 'CRM Lead' name: 'reference_doc',
? LeadsIcon value: callLog.value.data._lead == 'CRM Lead' ? 'Lead' : 'Deal',
: Dealsicon,
name: 'reference_doctype',
value:
callLog.value.data.reference_doctype == 'CRM Lead' ? 'Lead' : 'Deal',
link: () => { link: () => {
if (callLog.value.data.reference_doctype == 'CRM Lead') { if (callLog.value.data._lead) {
router.push({ router.push({
name: 'Lead', name: 'Lead',
params: { leadId: callLog.value.data.reference_docname }, params: { leadId: callLog.value.data._lead },
}) })
} else { } else {
router.push({ router.push({
name: 'Deal', name: 'Deal',
params: { dealId: callLog.value.data.reference_docname }, params: { dealId: callLog.value.data._deal },
}) })
} }
}, },
condition: () => callLog.value.data.reference_docname, condition: () => callLog.value.data._lead || callLog.value.data._deal,
}, },
{ {
icon: CalendarIcon, icon: CalendarIcon,
@ -207,7 +190,7 @@ const detailFields = computed(() => {
{ {
icon: NoteIcon, icon: NoteIcon,
name: 'note', name: 'note',
value: callNoteDoc.value?.doc, value: callNoteDoc.value,
}, },
] ]
@ -240,17 +223,7 @@ watch(show, (val) => {
return doc return doc
}, },
onSuccess: (doc) => { onSuccess: (doc) => {
if (!doc.note) { callNoteDoc.value = doc._notes?.[0] ?? null
callNoteDoc.value = null
return
}
callNoteDoc.value = createDocumentResource({
doctype: 'FCRM Note',
name: doc.note,
fields: ['title', 'content'],
cache: ['note', doc.note],
auto: true,
})
}, },
}) })
} }