1
0
forked from test/crm

fix: allow adding/editing note and task in call log

This commit is contained in:
Shariq Ansari 2025-01-22 19:06:31 +05:30
parent 9faa9f7171
commit 0a572c56f8
3 changed files with 134 additions and 11 deletions

View File

@ -53,15 +53,17 @@ def add_note_to_call_log(call_sid, note):
_note = frappe.get_doc(
{
"doctype": "FCRM Note",
"title": note.get("title", "Call Note"),
"content": note.get("content"),
}
).insert(ignore_permissions=True)
call_log = frappe.get_cached_doc("CRM Call Log", call_sid)
call_log.link_with_reference_doc("FCRM Note", _note.name)
call_log.save(ignore_permissions=True)
else:
_note = frappe.set_value("FCRM Note", note.get("name"), "content", note.get("content"))
call_log = frappe.get_cached_doc("CRM Call Log", call_sid)
call_log.link_with_reference_doc("FCRM Note", _note.name)
call_log.save(ignore_permissions=True)
return _note
@ -75,21 +77,30 @@ def add_task_to_call_log(call_sid, task):
"doctype": "CRM Task",
"title": task.get("title"),
"description": task.get("description"),
"assigned_to": task.get("assigned_to"),
"due_date": task.get("due_date"),
"status": task.get("status"),
"priority": task.get("priority"),
}
).insert(ignore_permissions=True)
call_log = frappe.get_doc("CRM Call Log", call_sid)
call_log.link_with_reference_doc("CRM Task", _task.name)
call_log.save(ignore_permissions=True)
else:
_task = frappe.get_doc("CRM Task", task.get("name"))
_task.update(
{
"title": task.get("title"),
"description": task.get("description"),
"assigned_to": task.get("assigned_to"),
"due_date": task.get("due_date"),
"status": task.get("status"),
"priority": task.get("priority"),
}
)
_task.save(ignore_permissions=True)
call_log = frappe.get_doc("CRM Call Log", call_sid)
call_log.link_with_reference_doc("CRM Task", _task.name)
call_log.save(ignore_permissions=True)
return _task

View File

@ -9,6 +9,30 @@
</h3>
</div>
<div class="flex items-center gap-1">
<Dropdown
:options="[
{
group: __('Options'),
hideLabel: true,
items: [
{
label: note?.name ? __('Edit note') : __('Add note'),
icon: NoteIcon,
onClick: addEditNote,
},
{
label: task?.name ? __('Edit task') : __('Add task'),
icon: TaskIcon,
onClick: addEditTask,
},
],
},
]"
>
<template #default>
<Button variant="ghost" icon="more-horizontal" />
</template>
</Dropdown>
<Button
v-if="isManager() && !isMobileView"
variant="ghost"
@ -84,6 +108,23 @@
/>
</FadedScrollableDiv>
</div>
<div
class="w-full cursor-pointer rounded border px-2 pt-1.5 text-base text-ink-gray-7"
v-else-if="field.name == 'task'"
@click="() => (showTaskModal = true)"
>
<FadedScrollableDiv class="max-h-24 min-h-16 overflow-y-auto">
<div
v-if="field.value?.title"
:class="[field.value?.description ? 'mb-1 font-bold' : '']"
v-html="field.value?.title"
/>
<div
v-if="field.value?.description"
v-html="field.value?.description"
/>
</FadedScrollableDiv>
</div>
<div v-else :class="field.color ? `text-${field.color}-600` : ''">
{{ field.value }}
</div>
@ -110,7 +151,8 @@
</div>
</template>
</Dialog>
<NoteModal v-model="showNoteModal" :note="callLog?.data?._notes?.[0]" />
<NoteModal v-model="showNoteModal" :note="note" @after="addNoteToCallLog" />
<TaskModal v-model="showTaskModal" :task="task" @after="addTaskToCallLog" />
</template>
<script setup>
@ -122,13 +164,15 @@ import LeadsIcon from '@/components/Icons/LeadsIcon.vue'
import Dealsicon from '@/components/Icons/DealsIcon.vue'
import CalendarIcon from '@/components/Icons/CalendarIcon.vue'
import NoteIcon from '@/components/Icons/NoteIcon.vue'
import TaskIcon from '@/components/Icons/TaskIcon.vue'
import CheckCircleIcon from '@/components/Icons/CheckCircleIcon.vue'
import NoteModal from '@/components/Modals/NoteModal.vue'
import TaskModal from '@/components/Modals/TaskModal.vue'
import FadedScrollableDiv from '@/components/FadedScrollableDiv.vue'
import { getCallLogDetail } from '@/utils/callLog'
import { usersStore } from '@/stores/users'
import { isMobileView } from '@/composables/settings'
import { FeatherIcon, Avatar, Tooltip, call } from 'frappe-ui'
import { FeatherIcon, Dropdown, Avatar, Tooltip, call } from 'frappe-ui'
import { ref, computed, h, nextTick } from 'vue'
import { useRouter } from 'vue-router'
@ -137,9 +181,24 @@ const router = useRouter()
const show = defineModel()
const showNoteModal = ref(false)
const showTaskModal = ref(false)
const callLog = defineModel('callLog')
const note = ref({
title: '',
content: '',
})
const task = ref({
title: '',
description: '',
assigned_to: '',
due_date: '',
status: 'Backlog',
priority: 'Low',
})
const detailFields = computed(() => {
if (!callLog.value?.data) return []
@ -149,6 +208,9 @@ const detailFields = computed(() => {
data[key] = getCallLogDetail(key, data)
}
note.value = data._notes?.[0] ?? null
task.value = data._tasks?.[0] ?? null
let details = [
{
icon: h(FeatherIcon, {
@ -215,6 +277,11 @@ const detailFields = computed(() => {
name: 'note',
value: data._notes?.[0] ?? null,
},
{
icon: TaskIcon,
name: 'task',
value: data._tasks?.[0] ?? null,
},
]
return details
@ -240,6 +307,50 @@ function openCallLogModal() {
show.value = false
})
}
function addEditNote() {
if (!note.value?.name) {
note.value = {
title: '',
content: '',
}
}
showNoteModal.value = true
}
function addEditTask() {
if (!task.value?.name) {
task.value = {
title: '',
description: '',
assigned_to: '',
due_date: '',
status: 'Backlog',
priority: 'Low',
}
}
showTaskModal.value = true
}
async function addNoteToCallLog(_note, insert_mode = false) {
note.value = _note
if (insert_mode && _note.name) {
await call('crm.integrations.api.add_note_to_call_log', {
call_sid: callLog.value?.data?.id,
note: _note,
})
}
}
async function addTaskToCallLog(_task, insert_mode = false) {
task.value = _task
if (insert_mode && _task.name) {
await call('crm.integrations.api.add_task_to_call_log', {
call_sid: callLog.value?.data?.id,
task: _task,
})
}
}
</script>
<style scoped>

View File

@ -187,7 +187,8 @@ async function updateTask() {
fieldname: _task.value,
})
if (d.name) {
tasks.value.reload()
tasks.value?.reload()
emit('after', d)
}
} else {
let d = await call('frappe.client.insert', {
@ -200,8 +201,8 @@ async function updateTask() {
})
if (d.name) {
capture('task_created')
tasks.value.reload()
emit('after')
tasks.value?.reload()
emit('after', d, true)
}
}
show.value = false