Merge branch 'main-hotfix' into mergify/bp/main-hotfix/pr-1100

This commit is contained in:
Shariq Ansari 2025-07-31 16:37:42 +05:30 committed by GitHub
commit 8fa583dbc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 526 additions and 618 deletions

View File

@ -1,20 +1,5 @@
import frappe import frappe
from crm.api.doc import get_fields_meta
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
@frappe.whitelist()
def get_deal(name):
deal = frappe.get_doc("CRM Deal", name)
deal.check_permission("read")
deal = deal.as_dict()
deal["fields_meta"] = get_fields_meta("CRM Deal")
deal["_form_script"] = get_form_script("CRM Deal")
return deal
@frappe.whitelist() @frappe.whitelist()
def get_deal_contacts(name): def get_deal_contacts(name):

View File

@ -1,16 +0,0 @@
import frappe
from crm.api.doc import get_fields_meta
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
@frappe.whitelist()
def get_lead(name):
lead = frappe.get_doc("CRM Lead", name)
lead.check_permission("read")
lead = lead.as_dict()
lead["fields_meta"] = get_fields_meta("CRM Lead")
lead["_form_script"] = get_form_script("CRM Lead")
return lead

View File

@ -8,21 +8,21 @@ else
echo "Creating new bench..." echo "Creating new bench..."
fi fi
bench init --skip-redis-config-generation frappe-bench bench init --skip-redis-config-generation frappe-bench --version version-15
cd frappe-bench cd frappe-bench
# Use containers instead of localhost # Use containers instead of localhost
bench set-mariadb-host mariadb bench set-mariadb-host mariadb
bench set-redis-cache-host redis:6379 bench set-redis-cache-host redis://redis:6379
bench set-redis-queue-host redis:6379 bench set-redis-queue-host redis://redis:6379
bench set-redis-socketio-host redis:6379 bench set-redis-socketio-host redis://redis:6379
# Remove redis, watch from Procfile # Remove redis, watch from Procfile
sed -i '/redis/d' ./Procfile sed -i '/redis/d' ./Procfile
sed -i '/watch/d' ./Procfile sed -i '/watch/d' ./Procfile
bench get-app crm --branch develop bench get-app crm --branch main
bench new-site crm.localhost \ bench new-site crm.localhost \
--force \ --force \
@ -32,8 +32,9 @@ bench new-site crm.localhost \
bench --site crm.localhost install-app crm bench --site crm.localhost install-app crm
bench --site crm.localhost set-config developer_mode 1 bench --site crm.localhost set-config developer_mode 1
bench --site crm.localhost clear-cache
bench --site crm.localhost set-config mute_emails 1 bench --site crm.localhost set-config mute_emails 1
bench --site crm.localhost set-config server_script_enabled 1
bench --site crm.localhost clear-cache
bench use crm.localhost bench use crm.localhost
bench start bench start

View File

@ -1,7 +1,7 @@
<template> <template>
<FrappeUIProvider> <FrappeUIProvider>
<Layout v-if="session().isLoggedIn"> <Layout v-if="session().isLoggedIn">
<router-view /> <router-view :key="$route.fullPath"/>
</Layout> </Layout>
<Dialogs /> <Dialogs />
</FrappeUIProvider> </FrappeUIProvider>

View File

@ -367,7 +367,7 @@
<div v-else-if="title == 'Data'" class="h-full flex flex-col px-3 sm:px-10"> <div v-else-if="title == 'Data'" class="h-full flex flex-col px-3 sm:px-10">
<DataFields <DataFields
:doctype="doctype" :doctype="doctype"
:docname="doc.data.name" :docname="docname"
@beforeSave="(data) => emit('beforeSave', data)" @beforeSave="(data) => emit('beforeSave', data)"
@afterSave="(data) => emit('afterSave', data)" @afterSave="(data) => emit('afterSave', data)"
/> />
@ -438,10 +438,9 @@
:doc="doc" :doc="doc"
/> />
<FilesUploader <FilesUploader
v-if="doc.data?.name"
v-model="showFilesUploader" v-model="showFilesUploader"
:doctype="doctype" :doctype="doctype"
:docname="doc.data.name" :docname="docname"
@after=" @after="
() => { () => {
all_activities.reload() all_activities.reload()
@ -514,6 +513,10 @@ const props = defineProps({
type: String, type: String,
default: 'CRM Lead', default: 'CRM Lead',
}, },
docname: {
type: String,
default: '',
},
tabs: { tabs: {
type: Array, type: Array,
default: () => [], default: () => [],
@ -524,11 +527,12 @@ const emit = defineEmits(['beforeSave', 'afterSave'])
const route = useRoute() const route = useRoute()
const doc = defineModel()
const reload = defineModel('reload') const reload = defineModel('reload')
const tabIndex = defineModel('tabIndex') const tabIndex = defineModel('tabIndex')
const { document: _document } = useDocument(props.doctype, doc.value.data.name) const { document: _document } = useDocument(props.doctype, props.docname)
const doc = computed(() => _document.doc || {})
const reload_email = ref(false) const reload_email = ref(false)
const modalRef = ref(null) const modalRef = ref(null)
@ -545,8 +549,8 @@ const changeTabTo = (tabName) => {
const all_activities = 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: props.docname },
cache: ['activity', doc.value.data.name], cache: ['activity', props.docname],
auto: true, auto: true,
transform: ([versions, calls, notes, tasks, attachments]) => { transform: ([versions, calls, notes, tasks, attachments]) => {
return { versions, calls, notes, tasks, attachments } return { versions, calls, notes, tasks, attachments }
@ -557,12 +561,12 @@ const showWhatsappTemplates = ref(false)
const whatsappMessages = createResource({ const whatsappMessages = createResource({
url: 'crm.api.whatsapp.get_whatsapp_messages', url: 'crm.api.whatsapp.get_whatsapp_messages',
cache: ['whatsapp_messages', doc.value.data.name], cache: ['whatsapp_messages', props.docname],
params: { params: {
reference_doctype: props.doctype, reference_doctype: props.doctype,
reference_name: doc.value.data.name, reference_name: props.docname,
}, },
auto: true, auto: whatsappEnabled.value,
transform: (data) => sortByCreation(data), transform: (data) => sortByCreation(data),
onSuccess: () => nextTick(() => scroll()), onSuccess: () => nextTick(() => scroll()),
}) })
@ -575,7 +579,7 @@ onMounted(() => {
$socket.on('whatsapp_message', (data) => { $socket.on('whatsapp_message', (data) => {
if ( if (
data.reference_doctype === props.doctype && data.reference_doctype === props.doctype &&
data.reference_name === doc.value.data.name data.reference_name === props.docname
) { ) {
whatsappMessages.reload() whatsappMessages.reload()
} }
@ -597,8 +601,8 @@ function sendTemplate(template) {
url: 'crm.api.whatsapp.send_whatsapp_template', url: 'crm.api.whatsapp.send_whatsapp_template',
params: { params: {
reference_doctype: props.doctype, reference_doctype: props.doctype,
reference_name: doc.value.data.name, reference_name: props.docname,
to: doc.value.data.mobile_no, to: doc.value.mobile_no,
template, template,
}, },
auto: true, auto: true,
@ -801,7 +805,7 @@ const callActions = computed(() => {
}, },
{ {
label: __('Make a Call'), label: __('Make a Call'),
onClick: () => makeCall(doc.data.mobile_no), onClick: () => makeCall(doc.value.mobile_no),
condition: () => callEnabled.value, condition: () => callEnabled.value,
}, },
] ]

View File

@ -140,7 +140,7 @@ const defaultActions = computed(() => {
{ {
icon: h(PhoneIcon, { class: 'h-4 w-4' }), icon: h(PhoneIcon, { class: 'h-4 w-4' }),
label: __('Make a Call'), label: __('Make a Call'),
onClick: () => makeCall(props.doc.data.mobile_no), onClick: () => makeCall(props.doc.mobile_no),
condition: () => callEnabled.value, condition: () => callEnabled.value,
}, },
{ {
@ -184,7 +184,7 @@ const callActions = computed(() => {
{ {
label: __('Make a Call'), label: __('Make a Call'),
icon: h(PhoneIcon, { class: 'h-4 w-4' }), icon: h(PhoneIcon, { class: 'h-4 w-4' }),
onClick: () => makeCall(props.doc.data.mobile_no), onClick: () => makeCall(props.doc.mobile_no),
condition: () => callEnabled.value, condition: () => callEnabled.value,
}, },
] ]

View File

@ -4,7 +4,7 @@
v-model:reloadTasks="activities" v-model:reloadTasks="activities"
:task="task" :task="task"
:doctype="doctype" :doctype="doctype"
:doc="doc.data?.name" :doc="doc?.name"
@after="redirect('tasks')" @after="redirect('tasks')"
/> />
<NoteModal <NoteModal
@ -12,7 +12,7 @@
v-model:reloadNotes="activities" v-model:reloadNotes="activities"
:note="note" :note="note"
:doctype="doctype" :doctype="doctype"
:doc="doc.data?.name" :doc="doc?.name"
@after="redirect('notes')" @after="redirect('notes')"
/> />
<CallLogModal <CallLogModal
@ -92,8 +92,8 @@ const referenceDoc = ref({})
function createCallLog() { function createCallLog() {
let doctype = props.doctype let doctype = props.doctype
let docname = props.doc.data?.name let docname = props.doc?.name
referenceDoc.value = { ...props.doc.data } referenceDoc.value = { ...props.doc }
callLog.value = { callLog.value = {
reference_doctype: doctype, reference_doctype: doctype,
reference_docname: docname, reference_docname: docname,

View File

@ -50,10 +50,12 @@
togglePrivate(attachment.name, attachment.is_private) togglePrivate(attachment.name, attachment.is_private)
" "
> >
<FeatherIcon <template #icon>
:name="attachment.is_private ? 'lock' : 'unlock'" <FeatherIcon
class="size-3 text-ink-gray-7" :name="attachment.is_private ? 'lock' : 'unlock'"
/> class="size-3 text-ink-gray-7"
/>
</template>
</Button> </Button>
</div> </div>
</Tooltip> </Tooltip>
@ -63,7 +65,12 @@
class="!size-5" class="!size-5"
@click.stop="() => deleteAttachment(attachment.name)" @click.stop="() => deleteAttachment(attachment.name)"
> >
<FeatherIcon name="trash-2" class="size-3 text-ink-gray-7" /> <template #icon>
<FeatherIcon
name="trash-2"
class="size-3 text-ink-gray-7"
/>
</template>
</Button> </Button>
</div> </div>
</Tooltip> </Tooltip>

View File

@ -107,9 +107,9 @@ function sendTextMessage(event) {
async function sendWhatsAppMessage() { async function sendWhatsAppMessage() {
let args = { let args = {
reference_doctype: props.doctype, reference_doctype: props.doctype,
reference_name: doc.value.data.name, reference_name: doc.value.name,
message: content.value, message: content.value,
to: doc.value.data.mobile_no, to: doc.value.mobile_no,
attach: whatsapp.value.attach || '', attach: whatsapp.value.attach || '',
reply_to: reply.value?.name || '', reply_to: reply.value?.name || '',
content_type: whatsapp.value.content_type, content_type: whatsapp.value.content_type,

View File

@ -45,7 +45,7 @@
onClick: () => { onClick: () => {
showEmailBox = false showEmailBox = false
newEmailEditor.subject = subject newEmailEditor.subject = subject
newEmailEditor.toEmails = doc.data.email ? [doc.data.email] : [] newEmailEditor.toEmails = doc.email ? [doc.email] : []
newEmailEditor.ccEmails = [] newEmailEditor.ccEmails = []
newEmailEditor.bccEmails = [] newEmailEditor.bccEmails = []
newEmailEditor.cc = false newEmailEditor.cc = false
@ -54,7 +54,7 @@
}, },
}" }"
:editable="showEmailBox" :editable="showEmailBox"
v-model="doc.data" v-model="doc"
v-model:attachments="attachments" v-model:attachments="attachments"
:doctype="doctype" :doctype="doctype"
:subject="subject" :subject="subject"
@ -79,7 +79,7 @@
}, },
}" }"
:editable="showCommentBox" :editable="showCommentBox"
v-model="doc.data" v-model="doc"
v-model:attachments="attachments" v-model:attachments="attachments"
:doctype="doctype" :doctype="doctype"
:placeholder="__('@John, can you please check this?')" :placeholder="__('@John, can you please check this?')"
@ -125,12 +125,12 @@ const attachments = ref([])
const subject = computed(() => { const subject = computed(() => {
let prefix = '' let prefix = ''
if (doc.value.data?.lead_name) { if (doc.value?.lead_name) {
prefix = doc.value.data.lead_name prefix = doc.value.lead_name
} else if (doc.value.data?.organization) { } else if (doc.value?.organization) {
prefix = doc.value.data.organization prefix = doc.value.organization
} }
return `${prefix} (#${doc.value.data.name})` return `${prefix} (#${doc.value.name})`
}) })
const signature = createResource({ const signature = createResource({
@ -199,7 +199,7 @@ async function sendMail() {
subject: subject, subject: subject,
content: newEmail.value, content: newEmail.value,
doctype: props.doctype, doctype: props.doctype,
name: doc.value.data.name, name: doc.value.name,
send_email: 1, send_email: 1,
sender: getUser().email, sender: getUser().email,
sender_full_name: getUser()?.full_name || undefined, sender_full_name: getUser()?.full_name || undefined,
@ -209,7 +209,7 @@ async function sendMail() {
async function sendComment() { async function sendComment() {
let comment = await call('frappe.desk.form.utils.add_comment', { let comment = await call('frappe.desk.form.utils.add_comment', {
reference_doctype: props.doctype, reference_doctype: props.doctype,
reference_name: doc.value.data.name, reference_name: doc.value.name,
content: newComment.value, content: newComment.value,
comment_email: getUser().email, comment_email: getUser().email,
comment_by: getUser()?.full_name || undefined, comment_by: getUser()?.full_name || undefined,

View File

@ -3,23 +3,39 @@ import { globalStore } from '@/stores/global'
import { showSettings, activeSettingsPage } from '@/composables/settings' import { showSettings, activeSettingsPage } from '@/composables/settings'
import { runSequentially, parseAssignees } from '@/utils' import { runSequentially, parseAssignees } from '@/utils'
import { createDocumentResource, createResource, toast } from 'frappe-ui' import { createDocumentResource, createResource, toast } from 'frappe-ui'
import { reactive } from 'vue' import { ref, reactive } from 'vue'
const documentsCache = {} const documentsCache = {}
const controllersCache = {} const controllersCache = {}
const assigneesCache = {} const assigneesCache = {}
export function useDocument(doctype, docname) { export function useDocument(doctype, docname) {
const { setupScript } = getScript(doctype) const { setupScript, scripts } = getScript(doctype)
documentsCache[doctype] = documentsCache[doctype] || {} documentsCache[doctype] = documentsCache[doctype] || {}
const error = ref('')
if (!documentsCache[doctype][docname || '']) { if (!documentsCache[doctype][docname || '']) {
if (docname) { if (docname) {
documentsCache[doctype][docname] = createDocumentResource({ documentsCache[doctype][docname] = createDocumentResource({
doctype: doctype, doctype: doctype,
name: docname, name: docname,
onSuccess: async () => await setupFormScript(), onSuccess: async () => await setupFormScript(),
onError: (err) => {
error.value = err
if (err.exc_type === 'DoesNotExistError') {
toast.error(__(err.messages[0] || 'Document does not exist'))
}
if (err.exc_type === 'PermissionError') {
toast.error(
__(
err.messages[0] ||
'You do not have permission to access this document',
),
)
}
},
setValue: { setValue: {
onSuccess: () => { onSuccess: () => {
triggerOnSave() triggerOnSave()
@ -262,6 +278,8 @@ export function useDocument(doctype, docname) {
return { return {
document: documentsCache[doctype][docname || ''], document: documentsCache[doctype][docname || ''],
assignees: assigneesCache[doctype][docname || ''], assignees: assigneesCache[doctype][docname || ''],
scripts,
error,
getControllers, getControllers,
triggerOnLoad, triggerOnLoad,
triggerOnBeforeCreate, triggerOnBeforeCreate,

View File

@ -1,5 +1,5 @@
<template> <template>
<LayoutHeader v-if="deal.data"> <LayoutHeader>
<template #left-header> <template #left-header>
<Breadcrumbs :items="breadcrumbs"> <Breadcrumbs :items="breadcrumbs">
<template #prefix="{ item }"> <template #prefix="{ item }">
@ -7,38 +7,30 @@
</template> </template>
</Breadcrumbs> </Breadcrumbs>
</template> </template>
<template #right-header> <template v-if="!errorTitle" #right-header>
<CustomActions <CustomActions
v-if="deal.data._customActions?.length" v-if="document._actions?.length"
:actions="deal.data._customActions" :actions="document._actions"
/> />
<CustomActions <CustomActions
v-if="document.actions?.length" v-if="document.actions?.length"
:actions="document.actions" :actions="document.actions"
/> />
<AssignTo <AssignTo v-model="assignees.data" :data="doc" doctype="CRM Deal" />
v-model="assignees.data"
:data="document.doc"
doctype="CRM Deal"
/>
<Dropdown <Dropdown
v-if="document.doc" v-if="doc"
:options=" :options="
statusOptions( statusOptions(
'deal', 'deal',
document.statuses?.length document.statuses?.length ? document.statuses : document._statuses,
? document.statuses
: deal.data._customStatuses,
triggerStatusChange, triggerStatusChange,
) )
" "
> >
<template #default="{ open }"> <template #default="{ open }">
<Button :label="document.doc.status"> <Button v-if="doc.status" :label="doc.status">
<template #prefix> <template #prefix>
<IndicatorIcon <IndicatorIcon :class="getDealStatus(doc.status).color" />
:class="getDealStatus(document.doc.status).color"
/>
</template> </template>
<template #suffix> <template #suffix>
<FeatherIcon <FeatherIcon
@ -51,16 +43,16 @@
</Dropdown> </Dropdown>
</template> </template>
</LayoutHeader> </LayoutHeader>
<div v-if="deal.data" class="flex h-full overflow-hidden"> <div v-if="doc.name" class="flex h-full overflow-hidden">
<Tabs as="div" v-model="tabIndex" :tabs="tabs"> <Tabs as="div" v-model="tabIndex" :tabs="tabs">
<template #tab-panel> <template #tab-panel>
<Activities <Activities
ref="activities" ref="activities"
doctype="CRM Deal" doctype="CRM Deal"
:docname="dealId"
:tabs="tabs" :tabs="tabs"
v-model:reload="reload" v-model:reload="reload"
v-model:tabIndex="tabIndex" v-model:tabIndex="tabIndex"
v-model="deal"
@beforeSave="beforeStatusChange" @beforeSave="beforeStatusChange"
@afterSave="reloadAssignees" @afterSave="reloadAssignees"
/> />
@ -69,9 +61,9 @@
<Resizer side="right" class="flex flex-col justify-between border-l"> <Resizer side="right" class="flex flex-col justify-between border-l">
<div <div
class="flex h-10.5 cursor-copy items-center border-b px-5 py-2.5 text-lg font-medium text-ink-gray-9" class="flex h-10.5 cursor-copy items-center border-b px-5 py-2.5 text-lg font-medium text-ink-gray-9"
@click="copyToClipboard(deal.data.name)" @click="copyToClipboard(dealId)"
> >
{{ __(deal.data.name) }} {{ __(dealId) }}
</div> </div>
<div class="flex items-center justify-start gap-5 border-b p-5"> <div class="flex items-center justify-start gap-5 border-b p-5">
<Tooltip :text="__('Organization logo')"> <Tooltip :text="__('Organization logo')">
@ -80,12 +72,12 @@
size="3xl" size="3xl"
class="size-12" class="size-12"
:label="title" :label="title"
:image="organization.data?.organization_logo" :image="organization?.organization_logo"
/> />
</div> </div>
</Tooltip> </Tooltip>
<div class="flex flex-col gap-2.5 truncate text-ink-gray-9"> <div class="flex flex-col gap-2.5 truncate text-ink-gray-9">
<Tooltip :text="organization.data?.name || __('Set an organization')"> <Tooltip :text="organization?.name || __('Set an organization')">
<div class="truncate text-2xl font-medium"> <div class="truncate text-2xl font-medium">
{{ title }} {{ title }}
</div> </div>
@ -102,9 +94,7 @@
<div> <div>
<Button <Button
@click=" @click="
deal.data.email doc.email ? openEmailBox() : toast.error(__('No email set'))
? openEmailBox()
: toast.error(__('No email set'))
" "
> >
<template #icon><Email2Icon /></template> <template #icon><Email2Icon /></template>
@ -115,8 +105,8 @@
<div> <div>
<Button <Button
@click=" @click="
deal.data.website doc.website
? openWebsite(deal.data.website) ? openWebsite(doc.website)
: toast.error(__('No website set')) : toast.error(__('No website set'))
" "
> >
@ -131,8 +121,6 @@
</Button> </Button>
</div> </div>
</Tooltip> </Tooltip>
<<<<<<< HEAD
=======
<Tooltip :text="__('Delete')"> <Tooltip :text="__('Delete')">
<div> <div>
<Button <Button
@ -143,13 +131,12 @@
/> />
</div> </div>
</Tooltip> </Tooltip>
>>>>>>> abc50182 (fix: update delete button click handler in Deal component)
</div> </div>
</div> </div>
</div> </div>
<SLASection <SLASection
v-if="deal.data.sla_status" v-if="doc.sla_status"
v-model="deal.data" v-model="doc"
@updateField="updateField" @updateField="updateField"
/> />
<div <div
@ -160,7 +147,7 @@
:sections="sections.data" :sections="sections.data"
:addContact="addContact" :addContact="addContact"
doctype="CRM Deal" doctype="CRM Deal"
:docname="deal.data.name" :docname="dealId"
@reload="sections.reload" @reload="sections.reload"
@beforeFieldChange="beforeStatusChange" @beforeFieldChange="beforeStatusChange"
@afterFieldChange="reloadAssignees" @afterFieldChange="reloadAssignees"
@ -175,7 +162,7 @@
(value, close) => { (value, close) => {
_contact = { _contact = {
first_name: value, first_name: value,
company_name: deal.data.organization, company_name: doc.organization,
} }
showContactModal = true showContactModal = true
close() close()
@ -311,7 +298,7 @@
:data="_organization" :data="_organization"
:options="{ :options="{
redirect: false, redirect: false,
afterInsert: (doc) => updateField('organization', doc.name), afterInsert: (_doc) => updateField('organization', _doc.name),
}" }"
/> />
<ContactModal <ContactModal
@ -320,14 +307,13 @@
:contact="_contact" :contact="_contact"
:options="{ :options="{
redirect: false, redirect: false,
afterInsert: (doc) => addContact(doc.name), afterInsert: (_doc) => addContact(_doc.name),
}" }"
/> />
<FilesUploader <FilesUploader
v-if="deal.data?.name"
v-model="showFilesUploader" v-model="showFilesUploader"
doctype="CRM Deal" doctype="CRM Deal"
:docname="deal.data.name" :docname="dealId"
@after=" @after="
() => { () => {
activities?.all_activities?.reload() activities?.all_activities?.reload()
@ -339,7 +325,7 @@
v-if="showDeleteLinkedDocModal" v-if="showDeleteLinkedDocModal"
v-model="showDeleteLinkedDocModal" v-model="showDeleteLinkedDocModal"
:doctype="'CRM Deal'" :doctype="'CRM Deal'"
:docname="props.dealId" :docname="dealId"
name="Deals" name="Deals"
/> />
<LostReasonModal <LostReasonModal
@ -349,6 +335,7 @@
/> />
</template> </template>
<script setup> <script setup>
import DeleteLinkedDocModal from '@/components/DeleteLinkedDocModal.vue'
import ErrorPage from '@/components/ErrorPage.vue' import ErrorPage from '@/components/ErrorPage.vue'
import Icon from '@/components/Icon.vue' import Icon from '@/components/Icon.vue'
import Resizer from '@/components/Resizer.vue' import Resizer from '@/components/Resizer.vue'
@ -399,7 +386,15 @@ import {
toast, toast,
} from 'frappe-ui' } from 'frappe-ui'
import { useOnboarding } from 'frappe-ui/frappe' import { useOnboarding } from 'frappe-ui/frappe'
import { ref, computed, h, onMounted, onBeforeUnmount, nextTick } from 'vue' import {
ref,
computed,
h,
onMounted,
onBeforeUnmount,
nextTick,
watch,
} from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { useActiveTabManager } from '@/composables/useActiveTabManager' import { useActiveTabManager } from '@/composables/useActiveTabManager'
@ -423,64 +418,73 @@ const props = defineProps({
const errorTitle = ref('') const errorTitle = ref('')
const errorMessage = ref('') const errorMessage = ref('')
const showDeleteLinkedDocModal = ref(false)
const deal = createResource({ const { triggerOnChange, assignees, document, scripts, error } = useDocument(
url: 'crm.fcrm.doctype.crm_deal.api.get_deal', 'CRM Deal',
params: { name: props.dealId }, props.dealId,
cache: ['deal', props.dealId], )
onSuccess: (data) => {
const doc = computed(() => document.doc || {})
watch(error, (err) => {
if (err) {
errorTitle.value = __(
err.exc_type == 'DoesNotExistError'
? 'Document not found'
: 'Error occurred',
)
errorMessage.value = __(err.messages?.[0] || 'An error occurred')
} else {
errorTitle.value = '' errorTitle.value = ''
errorMessage.value = '' errorMessage.value = ''
}
})
if (data.organization) { watch(
organization.update({ () => document.doc,
params: { doctype: 'CRM Organization', name: data.organization }, async (_doc) => {
if (scripts.data?.length) {
let s = await setupCustomizations(scripts.data, {
doc: _doc,
$dialog,
$socket,
router,
toast,
updateField,
createToast: toast.create,
deleteDoc: deleteDeal,
call,
}) })
organization.fetch() document._actions = s.actions || []
} document._statuses = s.statuses || []
setupCustomizations(deal, {
doc: data,
$dialog,
$socket,
router,
toast,
updateField,
createToast: toast.create,
deleteDoc: deleteDeal,
resource: {
deal,
dealContacts,
sections,
},
call,
})
},
onError: (err) => {
if (err.messages?.[0]) {
errorTitle.value = __('Not permitted')
errorMessage.value = __(err.messages?.[0])
} else {
router.push({ name: 'Deals' })
} }
}, },
}) { once: true },
)
const organization = createResource({ const organizationDocument = ref(null)
url: 'frappe.client.get',
onSuccess: (data) => (deal.data._organizationObj = data), watch(
}) () => doc.value.organization,
(org) => {
if (org && !organizationDocument.value?.doc) {
let { document: _organizationDocument } = useDocument(
'CRM Organization',
org,
)
organizationDocument.value = _organizationDocument
}
},
{ immediate: true },
)
const organization = computed(() => organizationDocument.value?.doc || {})
onMounted(() => { onMounted(() => {
$socket.on('crm_customer_created', () => { $socket.on('crm_customer_created', () => {
toast.success(__('Customer created successfully')) toast.success(__('Customer created successfully'))
}) })
if (deal.data) {
organization.data = deal.data._organizationObj
return
}
deal.fetch()
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
@ -491,45 +495,6 @@ const reload = ref(false)
const showOrganizationModal = ref(false) const showOrganizationModal = ref(false)
const showFilesUploader = ref(false) const showFilesUploader = ref(false)
const _organization = ref({}) const _organization = ref({})
const showDeleteLinkedDocModal = ref(false)
async function deleteDealWithModal() {
showDeleteLinkedDocModal.value = true
}
function updateDeal(fieldname, value, callback) {
value = Array.isArray(fieldname) ? '' : value
if (validateRequired(fieldname, value)) return
createResource({
url: 'frappe.client.set_value',
params: {
doctype: 'CRM Deal',
name: props.dealId,
fieldname,
value,
},
auto: true,
onSuccess: () => {
deal.reload()
reload.value = true
toast.success(__('Deal updated'))
callback?.()
},
onError: (err) => {
toast.error(__('Error updating deal: {0}', [err.messages?.[0]]))
},
})
}
function validateRequired(fieldname, value) {
let meta = deal.data.fields_meta || {}
if (meta[fieldname]?.reqd && !value) {
toast.error(__('{0} is a required field', [meta[fieldname].label]))
return true
}
return false
}
const breadcrumbs = computed(() => { const breadcrumbs = computed(() => {
let items = [{ label: __('Deals'), route: { name: 'Deals' } }] let items = [{ label: __('Deals'), route: { name: 'Deals' } }]
@ -551,14 +516,14 @@ const breadcrumbs = computed(() => {
items.push({ items.push({
label: title.value, label: title.value,
route: { name: 'Deal', params: { dealId: deal.data.name } }, route: { name: 'Deal', params: { dealId: props.dealId } },
}) })
return items return items
}) })
const title = computed(() => { const title = computed(() => {
let t = doctypeMeta['CRM Deal']?.title_field || 'name' let t = doctypeMeta['CRM Deal']?.title_field || 'name'
return deal.data?.[t] || props.dealId return doc.value?.[t] || props.dealId
}) })
usePageMeta(() => { usePageMeta(() => {
@ -619,6 +584,7 @@ const tabs = computed(() => {
] ]
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true)) return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
}) })
const { tabIndex } = useActiveTabManager(tabs, 'lastDealTab') const { tabIndex } = useActiveTabManager(tabs, 'lastDealTab')
const sections = createResource({ const sections = createResource({
@ -743,23 +709,40 @@ function triggerCall() {
makeCall(mobile_no) makeCall(mobile_no)
} }
function updateField(name, value, callback) { async function triggerStatusChange(value) {
await triggerOnChange('status', value)
setLostReason()
}
function updateField(name, value) {
if (name == 'status' && !isOnboardingStepsCompleted.value) { if (name == 'status' && !isOnboardingStepsCompleted.value) {
updateOnboardingStep('change_deal_status') updateOnboardingStep('change_deal_status')
} }
updateDeal(name, value, () => { value = Array.isArray(name) ? '' : value
deal.data[name] = value let oldValues = Array.isArray(name) ? {} : doc.value[name]
callback?.()
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = value))
} else {
doc.value[name] = value
}
document.save.submit(null, {
onSuccess: () => (reload.value = true),
onError: (err) => {
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = oldValues[field]))
} else {
doc.value[name] = oldValues
}
toast.error(err.messages?.[0] || __('Error updating field'))
},
}) })
} }
async function deleteDeal(name) { function deleteDeal() {
await call('frappe.client.delete', { showDeleteLinkedDocModal.value = true
doctype: 'CRM Deal',
name,
})
router.push({ name: 'Deals' })
} }
const activities = ref(null) const activities = ref(null)
@ -772,16 +755,6 @@ function openEmailBox() {
nextTick(() => (activities.value.emailBox.show = true)) nextTick(() => (activities.value.emailBox.show = true))
} }
const { assignees, document, triggerOnChange } = useDocument(
'CRM Deal',
props.dealId,
)
async function triggerStatusChange(value) {
await triggerOnChange('status', value)
setLostReason()
}
const showLostReasonModal = ref(false) const showLostReasonModal = ref(false)
function setLostReason() { function setLostReason() {
@ -798,7 +771,10 @@ function setLostReason() {
} }
function beforeStatusChange(data) { function beforeStatusChange(data) {
if (data?.hasOwnProperty('status') && getDealStatus(data.status).type == 'Lost') { if (
data?.hasOwnProperty('status') &&
getDealStatus(data.status).type == 'Lost'
) {
setLostReason() setLostReason()
} else { } else {
document.save.submit(null, { document.save.submit(null, {

View File

@ -1,5 +1,5 @@
<template> <template>
<LayoutHeader v-if="lead.data"> <LayoutHeader>
<template #left-header> <template #left-header>
<Breadcrumbs :items="breadcrumbs"> <Breadcrumbs :items="breadcrumbs">
<template #prefix="{ item }"> <template #prefix="{ item }">
@ -7,38 +7,30 @@
</template> </template>
</Breadcrumbs> </Breadcrumbs>
</template> </template>
<template #right-header> <template v-if="!errorTitle" #right-header>
<CustomActions <CustomActions
v-if="lead.data._customActions?.length" v-if="document._actions?.length"
:actions="lead.data._customActions" :actions="document._actions"
/> />
<CustomActions <CustomActions
v-if="document.actions?.length" v-if="document.actions?.length"
:actions="document.actions" :actions="document.actions"
/> />
<AssignTo <AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
v-model="assignees.data"
:data="document.doc"
doctype="CRM Lead"
/>
<Dropdown <Dropdown
v-if="document.doc" v-if="doc"
:options=" :options="
statusOptions( statusOptions(
'lead', 'lead',
document.statuses?.length document.statuses?.length ? document.statuses : document._statuses,
? document.statuses
: lead.data._customStatuses,
triggerStatusChange, triggerStatusChange,
) )
" "
> >
<template #default="{ open }"> <template #default="{ open }">
<Button :label="document.doc.status"> <Button v-if="doc.status" :label="doc.status">
<template #prefix> <template #prefix>
<IndicatorIcon <IndicatorIcon :class="getLeadStatus(doc.status).color" />
:class="getLeadStatus(document.doc.status).color"
/>
</template> </template>
<template #suffix> <template #suffix>
<FeatherIcon <FeatherIcon
@ -56,16 +48,16 @@
/> />
</template> </template>
</LayoutHeader> </LayoutHeader>
<div v-if="lead?.data" class="flex h-full overflow-hidden"> <div v-if="doc.name" class="flex h-full overflow-hidden">
<Tabs as="div" v-model="tabIndex" :tabs="tabs"> <Tabs as="div" v-model="tabIndex" :tabs="tabs">
<template #tab-panel> <template #tab-panel>
<Activities <Activities
ref="activities" ref="activities"
doctype="CRM Lead" doctype="CRM Lead"
:docname="leadId"
:tabs="tabs" :tabs="tabs"
v-model:reload="reload" v-model:reload="reload"
v-model:tabIndex="tabIndex" v-model:tabIndex="tabIndex"
v-model="lead"
@beforeSave="saveChanges" @beforeSave="saveChanges"
@afterSave="reloadAssignees" @afterSave="reloadAssignees"
/> />
@ -74,9 +66,9 @@
<Resizer class="flex flex-col justify-between border-l" side="right"> <Resizer class="flex flex-col justify-between border-l" side="right">
<div <div
class="flex h-10.5 cursor-copy items-center border-b px-5 py-2.5 text-lg font-medium text-ink-gray-9" class="flex h-10.5 cursor-copy items-center border-b px-5 py-2.5 text-lg font-medium text-ink-gray-9"
@click="copyToClipboard(lead.data.name)" @click="copyToClipboard(leadId)"
> >
{{ __(lead.data.name) }} {{ __(leadId) }}
</div> </div>
<FileUploader <FileUploader
@success="(file) => updateField('image', file.file_url)" @success="(file) => updateField('image', file.file_url)"
@ -89,17 +81,17 @@
size="3xl" size="3xl"
class="size-12" class="size-12"
:label="title" :label="title"
:image="lead.data.image" :image="doc.image"
/> />
<component <component
:is="lead.data.image ? Dropdown : 'div'" :is="doc.image ? Dropdown : 'div'"
v-bind=" v-bind="
lead.data.image doc.image
? { ? {
options: [ options: [
{ {
icon: 'upload', icon: 'upload',
label: lead.data.image label: doc.image
? __('Change image') ? __('Change image')
: __('Upload image'), : __('Upload image'),
onClick: openFileSelector, onClick: openFileSelector,
@ -127,7 +119,7 @@
</component> </component>
</div> </div>
<div class="flex flex-col gap-2.5 truncate"> <div class="flex flex-col gap-2.5 truncate">
<Tooltip :text="lead.data.lead_name || __('Set first name')"> <Tooltip :text="doc.lead_name || __('Set first name')">
<div class="truncate text-2xl font-medium text-ink-gray-9"> <div class="truncate text-2xl font-medium text-ink-gray-9">
{{ title }} {{ title }}
</div> </div>
@ -138,8 +130,8 @@
<Button <Button
@click=" @click="
() => () =>
lead.data.mobile_no doc.mobile_no
? makeCall(lead.data.mobile_no) ? makeCall(doc.mobile_no)
: toast.error(__('No phone number set')) : toast.error(__('No phone number set'))
" "
> >
@ -153,7 +145,7 @@
<div> <div>
<Button <Button
@click=" @click="
lead.data.email doc.email
? openEmailBox() ? openEmailBox()
: toast.error(__('No email set')) : toast.error(__('No email set'))
" "
@ -168,8 +160,8 @@
<div> <div>
<Button <Button
@click=" @click="
lead.data.website doc.website
? openWebsite(lead.data.website) ? openWebsite(doc.website)
: toast.error(__('No website set')) : toast.error(__('No website set'))
" "
> >
@ -188,6 +180,16 @@
</Button> </Button>
</div> </div>
</Tooltip> </Tooltip>
<Tooltip :text="__('Delete')">
<div>
<Button
@click="deleteLead"
variant="subtle"
theme="red"
icon="trash-2"
/>
</div>
</Tooltip>
</div> </div>
<ErrorMessage :message="__(error)" /> <ErrorMessage :message="__(error)" />
</div> </div>
@ -195,8 +197,8 @@
</template> </template>
</FileUploader> </FileUploader>
<SLASection <SLASection
v-if="lead.data.sla_status" v-if="doc.sla_status"
v-model="lead.data" v-model="doc"
@updateField="updateField" @updateField="updateField"
/> />
<div <div
@ -206,7 +208,7 @@
<SidePanelLayout <SidePanelLayout
:sections="sections.data" :sections="sections.data"
doctype="CRM Lead" doctype="CRM Lead"
:docname="lead.data.name" :docname="leadId"
@reload="sections.reload" @reload="sections.reload"
@afterFieldChange="reloadAssignees" @afterFieldChange="reloadAssignees"
/> />
@ -221,13 +223,12 @@
<ConvertToDealModal <ConvertToDealModal
v-if="showConvertToDealModal" v-if="showConvertToDealModal"
v-model="showConvertToDealModal" v-model="showConvertToDealModal"
:lead="lead.data" :lead="doc"
/> />
<FilesUploader <FilesUploader
v-if="lead.data?.name"
v-model="showFilesUploader" v-model="showFilesUploader"
doctype="CRM Lead" doctype="CRM Lead"
:docname="lead.data.name" :docname="leadId"
@after=" @after="
() => { () => {
activities?.all_activities?.reload() activities?.all_activities?.reload()
@ -239,11 +240,12 @@
v-if="showDeleteLinkedDocModal" v-if="showDeleteLinkedDocModal"
v-model="showDeleteLinkedDocModal" v-model="showDeleteLinkedDocModal"
:doctype="'CRM Lead'" :doctype="'CRM Lead'"
:docname="props.leadId" :docname="leadId"
name="Leads" name="Leads"
/> />
</template> </template>
<script setup> <script setup>
import DeleteLinkedDocModal from '@/components/DeleteLinkedDocModal.vue'
import ErrorPage from '@/components/ErrorPage.vue' import ErrorPage from '@/components/ErrorPage.vue'
import Icon from '@/components/Icon.vue' import Icon from '@/components/Icon.vue'
import Resizer from '@/components/Resizer.vue' import Resizer from '@/components/Resizer.vue'
@ -293,7 +295,7 @@ import {
usePageMeta, usePageMeta,
toast, toast,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, computed, onMounted, watch, nextTick } from 'vue' import { ref, computed, watch, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import { useActiveTabManager } from '@/composables/useActiveTabManager' import { useActiveTabManager } from '@/composables/useActiveTabManager'
@ -312,93 +314,56 @@ const props = defineProps({
}, },
}) })
const reload = ref(false)
const activities = ref(null)
const errorTitle = ref('') const errorTitle = ref('')
const errorMessage = ref('') const errorMessage = ref('')
const showDeleteLinkedDocModal = ref(false) const showDeleteLinkedDocModal = ref(false)
const showConvertToDealModal = ref(false) const showConvertToDealModal = ref(false)
const showFilesUploader = ref(false)
const { triggerOnChange, assignees, document } = useDocument( const { triggerOnChange, assignees, document, scripts, error } = useDocument(
'CRM Lead', 'CRM Lead',
props.leadId, props.leadId,
) )
async function triggerStatusChange(value) { const doc = computed(() => document.doc || {})
await triggerOnChange('status', value)
document.save.submit()
}
const lead = createResource({ watch(error, (err) => {
url: 'crm.fcrm.doctype.crm_lead.api.get_lead', if (err) {
params: { name: props.leadId }, errorTitle.value = __(
cache: ['lead', props.leadId], err.exc_type == 'DoesNotExistError'
onSuccess: (data) => { ? 'Document not found'
: 'Error occurred',
)
errorMessage.value = __(err.messages?.[0] || 'An error occurred')
} else {
errorTitle.value = '' errorTitle.value = ''
errorMessage.value = '' errorMessage.value = ''
setupCustomizations(lead, { }
doc: data, })
$dialog,
$socket, watch(
router, () => document.doc,
toast, async (_doc) => {
updateField, if (scripts.data?.length) {
createToast: toast.create, let s = await setupCustomizations(scripts.data, {
deleteDoc: deleteLead, doc: _doc,
resource: { lead, sections }, $dialog,
call, $socket,
}) router,
}, toast,
onError: (err) => { updateField,
if (err.messages?.[0]) { createToast: toast.create,
errorTitle.value = __('Not permitted') deleteDoc: deleteLead,
errorMessage.value = __(err.messages?.[0]) call,
} else { })
router.push({ name: 'Leads' }) document._actions = s.actions || []
document._statuses = s.statuses || []
} }
}, },
}) { once: true },
)
onMounted(() => {
if (lead.data) return
lead.fetch()
})
const reload = ref(false)
const showFilesUploader = ref(false)
function updateLead(fieldname, value, callback) {
value = Array.isArray(fieldname) ? '' : value
if (!Array.isArray(fieldname) && validateRequired(fieldname, value)) return
createResource({
url: 'frappe.client.set_value',
params: {
doctype: 'CRM Lead',
name: props.leadId,
fieldname,
value,
},
auto: true,
onSuccess: () => {
lead.reload()
reload.value = true
toast.success(__('Lead updated successfully'))
callback?.()
},
onError: (err) => {
toast.error(err.messages?.[0] || __('Error updating lead'))
},
})
}
function validateRequired(fieldname, value) {
let meta = lead.data.fields_meta || {}
if (meta[fieldname]?.reqd && !value) {
toast.error(__('{0} is a required field', [meta[fieldname].label]))
return true
}
return false
}
const breadcrumbs = computed(() => { const breadcrumbs = computed(() => {
let items = [{ label: __('Leads'), route: { name: 'Leads' } }] let items = [{ label: __('Leads'), route: { name: 'Leads' } }]
@ -420,21 +385,18 @@ const breadcrumbs = computed(() => {
items.push({ items.push({
label: title.value, label: title.value,
route: { name: 'Lead', params: { leadId: lead.data.name } }, route: { name: 'Lead', params: { leadId: props.leadId } },
}) })
return items return items
}) })
const title = computed(() => { const title = computed(() => {
let t = doctypeMeta['CRM Lead']?.title_field || 'name' let t = doctypeMeta['CRM Lead']?.title_field || 'name'
return lead.data?.[t] || props.leadId return doc?.[t] || props.leadId
}) })
usePageMeta(() => { usePageMeta(() => {
return { return { title: title.value, icon: brand.favicon }
title: title.value,
icon: brand.favicon,
}
}) })
const tabs = computed(() => { const tabs = computed(() => {
@ -491,17 +453,6 @@ const tabs = computed(() => {
const { tabIndex, changeTabTo } = useActiveTabManager(tabs, 'lastLeadTab') const { tabIndex, changeTabTo } = useActiveTabManager(tabs, 'lastLeadTab')
watch(tabs, (value) => {
if (value && route.params.tabName) {
let index = value.findIndex(
(tab) => tab.name.toLowerCase() === route.params.tabName.toLowerCase(),
)
if (index !== -1) {
tabIndex.value = index
}
}
})
const sections = createResource({ const sections = createResource({
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections', url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections',
cache: ['sidePanelSections', 'CRM Lead'], cache: ['sidePanelSections', 'CRM Lead'],
@ -509,27 +460,38 @@ const sections = createResource({
auto: true, auto: true,
}) })
function updateField(name, value, callback) { async function triggerStatusChange(value) {
updateLead(name, value, () => { await triggerOnChange('status', value)
lead.data[name] = value document.save.submit()
callback?.() }
function updateField(name, value) {
value = Array.isArray(name) ? '' : value
let oldValues = Array.isArray(name) ? {} : doc.value[name]
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = value))
} else {
doc.value[name] = value
}
document.save.submit(null, {
onSuccess: () => (reload.value = true),
onError: (err) => {
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = oldValues[field]))
} else {
doc.value[name] = oldValues
}
toast.error(err.messages?.[0] || __('Error updating field'))
},
}) })
} }
async function deleteLead(name) { function deleteLead() {
await call('frappe.client.delete', {
doctype: 'CRM Lead',
name,
})
router.push({ name: 'Leads' })
}
async function deleteLeadWithModal(name) {
showDeleteLinkedDocModal.value = true showDeleteLinkedDocModal.value = true
} }
const activities = ref(null)
function openEmailBox() { function openEmailBox() {
let currentTab = tabs.value[tabIndex.value] let currentTab = tabs.value[tabIndex.value]
if (!['Emails', 'Comments', 'Activities'].includes(currentTab.name)) { if (!['Emails', 'Comments', 'Activities'].includes(currentTab.name)) {

View File

@ -1,5 +1,5 @@
<template> <template>
<LayoutHeader v-if="deal.data"> <LayoutHeader>
<header <header
class="relative flex h-10.5 items-center justify-between gap-2 py-2.5 pl-2" class="relative flex h-10.5 items-center justify-between gap-2 py-2.5 pl-2"
> >
@ -10,23 +10,21 @@
</Breadcrumbs> </Breadcrumbs>
<div class="absolute right-0"> <div class="absolute right-0">
<Dropdown <Dropdown
v-if="document.doc" v-if="doc"
:options=" :options="
statusOptions( statusOptions(
'deal', 'deal',
document.statuses?.length document.statuses?.length
? document.statuses ? document.statuses
: deal.data._customStatuses, : document._statuses,
triggerStatusChange, triggerStatusChange,
) )
" "
> >
<template #default="{ open }"> <template #default="{ open }">
<Button :label="document.doc.status"> <Button v-if="doc.status" :label="doc.status">
<template #prefix> <template #prefix>
<IndicatorIcon <IndicatorIcon :class="getDealStatus(doc.status).color" />
:class="getDealStatus(document.doc.status).color"
/>
</template> </template>
<template #suffix> <template #suffix>
<FeatherIcon <FeatherIcon
@ -41,18 +39,14 @@
</header> </header>
</LayoutHeader> </LayoutHeader>
<div <div
v-if="deal.data" v-if="doc.name"
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5" class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
> >
<AssignTo <AssignTo v-model="assignees.data" :data="doc" doctype="CRM Deal" />
v-model="assignees.data"
:data="document.doc"
doctype="CRM Deal"
/>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<CustomActions <CustomActions
v-if="deal.data._customActions?.length" v-if="document._actions?.length"
:actions="deal.data._customActions" :actions="document._actions"
/> />
<CustomActions <CustomActions
v-if="document.actions?.length" v-if="document.actions?.length"
@ -60,14 +54,14 @@
/> />
</div> </div>
</div> </div>
<div v-if="deal.data" class="flex h-full overflow-hidden"> <div v-if="doc.name" class="flex h-full overflow-hidden">
<Tabs as="div" v-model="tabIndex" :tabs="tabs" class="overflow-auto"> <Tabs as="div" v-model="tabIndex" :tabs="tabs" class="overflow-auto">
<TabList class="!px-3" /> <TabList class="!px-3" />
<TabPanel v-slot="{ tab }"> <TabPanel v-slot="{ tab }">
<div v-if="tab.name == 'Details'"> <div v-if="tab.name == 'Details'">
<SLASection <SLASection
v-if="deal.data.sla_status" v-if="doc.sla_status"
v-model="deal.data" v-model="doc"
@updateField="updateField" @updateField="updateField"
/> />
<div <div
@ -77,7 +71,7 @@
<SidePanelLayout <SidePanelLayout
:sections="sections.data" :sections="sections.data"
doctype="CRM Deal" doctype="CRM Deal"
:docname="deal.data.name" :docname="dealId"
@reload="sections.reload" @reload="sections.reload"
@beforeFieldChange="beforeStatusChange" @beforeFieldChange="beforeStatusChange"
@afterFieldChange="reloadAssignees" @afterFieldChange="reloadAssignees"
@ -92,7 +86,7 @@
(value, close) => { (value, close) => {
_contact = { _contact = {
first_name: value, first_name: value,
company_name: deal.data.organization, company_name: doc.organization,
} }
showContactModal = true showContactModal = true
close() close()
@ -220,23 +214,28 @@
<Activities <Activities
v-else v-else
doctype="CRM Deal" doctype="CRM Deal"
:docname="dealId"
:tabs="tabs" :tabs="tabs"
v-model:reload="reload" v-model:reload="reload"
v-model:tabIndex="tabIndex" v-model:tabIndex="tabIndex"
v-model="deal"
@beforeSave="beforeStatusChange" @beforeSave="beforeStatusChange"
@afterSave="reloadAssignees" @afterSave="reloadAssignees"
/> />
</TabPanel> </TabPanel>
</Tabs> </Tabs>
</div> </div>
<ErrorPage
v-else-if="errorTitle"
:errorTitle="errorTitle"
:errorMessage="errorMessage"
/>
<OrganizationModal <OrganizationModal
v-if="showOrganizationModal" v-if="showOrganizationModal"
v-model="showOrganizationModal" v-model="showOrganizationModal"
:data="_organization" :data="_organization"
:options="{ :options="{
redirect: false, redirect: false,
afterInsert: (doc) => updateField('organization', doc.name), afterInsert: (_doc) => updateField('organization', _doc.name),
}" }"
/> />
<ContactModal <ContactModal
@ -245,9 +244,16 @@
:contact="_contact" :contact="_contact"
:options="{ :options="{
redirect: false, redirect: false,
afterInsert: (doc) => addContact(doc.name), afterInsert: (_doc) => addContact(_doc.name),
}" }"
/> />
<DeleteLinkedDocModal
v-if="showDeleteLinkedDocModal"
v-model="showDeleteLinkedDocModal"
:doctype="'CRM Deal'"
:docname="dealId"
name="Deals"
/>
<LostReasonModal <LostReasonModal
v-if="showLostReasonModal" v-if="showLostReasonModal"
v-model="showLostReasonModal" v-model="showLostReasonModal"
@ -255,6 +261,8 @@
/> />
</template> </template>
<script setup> <script setup>
import DeleteLinkedDocModal from '@/components/DeleteLinkedDocModal.vue'
import ErrorPage from '@/components/ErrorPage.vue'
import Icon from '@/components/Icon.vue' import Icon from '@/components/Icon.vue'
import DetailsIcon from '@/components/Icons/DetailsIcon.vue' import DetailsIcon from '@/components/Icons/DetailsIcon.vue'
import LoadingIndicator from '@/components/Icons/LoadingIndicator.vue' import LoadingIndicator from '@/components/Icons/LoadingIndicator.vue'
@ -306,7 +314,7 @@ import {
usePageMeta, usePageMeta,
toast, toast,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, computed, h, onMounted } from 'vue' import { ref, computed, h, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
const { brand } = getSettings() const { brand } = getSettings()
@ -323,86 +331,57 @@ const props = defineProps({
}, },
}) })
const deal = createResource({ const errorTitle = ref('')
url: 'crm.fcrm.doctype.crm_deal.api.get_deal', const errorMessage = ref('')
params: { name: props.dealId }, const showDeleteLinkedDocModal = ref(false)
cache: ['deal', props.dealId],
onSuccess: (data) => { const { triggerOnChange, assignees, document, scripts, error } = useDocument(
if (data.organization) { 'CRM Deal',
organization.update({ props.dealId,
params: { doctype: 'CRM Organization', name: data.organization }, )
const doc = computed(() => document.doc || {})
watch(error, (err) => {
if (err) {
errorTitle.value = __(
err.exc_type == 'DoesNotExistError'
? 'Document not found'
: 'Error occurred',
)
errorMessage.value = __(err.messages?.[0] || 'An error occurred')
} else {
errorTitle.value = ''
errorMessage.value = ''
}
})
watch(
() => document.doc,
async (_doc) => {
if (scripts.data?.length) {
let s = await setupCustomizations(scripts.data, {
doc: _doc,
$dialog,
$socket,
router,
toast,
updateField,
createToast: toast.create,
deleteDoc: deleteDeal,
call,
}) })
organization.fetch() document._actions = s.actions || []
document._statuses = s.statuses || []
} }
setupCustomizations(deal, {
doc: data,
$dialog,
$socket,
router,
toast,
updateField,
createToast: toast.create,
deleteDoc: deleteDeal,
resource: {
deal,
dealContacts,
sections,
},
call,
})
}, },
}) { once: true },
)
const organization = createResource({
url: 'frappe.client.get',
onSuccess: (data) => (deal.data._organizationObj = data),
})
onMounted(() => {
if (deal.data) return
deal.fetch()
})
const reload = ref(false) const reload = ref(false)
const showOrganizationModal = ref(false) const showOrganizationModal = ref(false)
const _organization = ref({}) const _organization = ref({})
function updateDeal(fieldname, value, callback) {
value = Array.isArray(fieldname) ? '' : value
if (validateRequired(fieldname, value)) return
createResource({
url: 'frappe.client.set_value',
params: {
doctype: 'CRM Deal',
name: props.dealId,
fieldname,
value,
},
auto: true,
onSuccess: () => {
deal.reload()
reload.value = true
toast.success(__('Deal updated'))
callback?.()
},
onError: (err) => {
toast.error(err.messages?.[0] || __('Error updating deal'))
},
})
}
function validateRequired(fieldname, value) {
let meta = deal.data.fields_meta || {}
if (meta[fieldname]?.reqd && !value) {
toast.error(__('{0} is a required field', [meta[fieldname].label]))
return true
}
return false
}
const breadcrumbs = computed(() => { const breadcrumbs = computed(() => {
let items = [{ label: __('Deals'), route: { name: 'Deals' } }] let items = [{ label: __('Deals'), route: { name: 'Deals' } }]
@ -423,14 +402,14 @@ const breadcrumbs = computed(() => {
items.push({ items.push({
label: title.value, label: title.value,
route: { name: 'Deal', params: { dealId: deal.data.name } }, route: { name: 'Deal', params: { dealId: props.dealId } },
}) })
return items return items
}) })
const title = computed(() => { const title = computed(() => {
let t = doctypeMeta['CRM Deal']?.title_field || 'name' let t = doctypeMeta['CRM Deal']?.title_field || 'name'
return deal.data?.[t] || props.dealId return doc.value?.[t] || props.dealId
}) })
usePageMeta(() => { usePageMeta(() => {
@ -614,26 +593,33 @@ const dealContacts = createResource({
}, },
}) })
function updateField(name, value, callback) { function updateField(name, value) {
updateDeal(name, value, () => { value = Array.isArray(name) ? '' : value
deal.data[name] = value let oldValues = Array.isArray(name) ? {} : doc.value[name]
callback?.()
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = value))
} else {
doc.value[name] = value
}
document.save.submit(null, {
onSuccess: () => (reload.value = true),
onError: (err) => {
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = oldValues[field]))
} else {
doc.value[name] = oldValues
}
toast.error(err.messages?.[0] || __('Error updating field'))
},
}) })
} }
async function deleteDeal(name) { function deleteDeal() {
await call('frappe.client.delete', { showDeleteLinkedDocModal.value = true
doctype: 'CRM Deal',
name,
})
router.push({ name: 'Deals' })
} }
const { assignees, document, triggerOnChange } = useDocument(
'CRM Deal',
props.dealId,
)
async function triggerStatusChange(value) { async function triggerStatusChange(value) {
await triggerOnChange('status', value) await triggerOnChange('status', value)
setLostReason() setLostReason()
@ -643,9 +629,9 @@ const showLostReasonModal = ref(false)
function setLostReason() { function setLostReason() {
if ( if (
getDealStatus(document.doc.status).type !== 'Lost' || getDealStatus(doc.status).type !== 'Lost' ||
(document.doc.lost_reason && document.doc.lost_reason !== 'Other') || (doc.lost_reason && doc.lost_reason !== 'Other') ||
(document.doc.lost_reason === 'Other' && document.doc.lost_notes) (doc.lost_reason === 'Other' && doc.lost_notes)
) { ) {
document.save.submit() document.save.submit()
return return
@ -655,7 +641,10 @@ function setLostReason() {
} }
function beforeStatusChange(data) { function beforeStatusChange(data) {
if (data?.hasOwnProperty('status') && getDealStatus(data.status).type == 'Lost') { if (
data?.hasOwnProperty('status') &&
getDealStatus(data.status).type == 'Lost'
) {
setLostReason() setLostReason()
} else { } else {
document.save.submit(null, { document.save.submit(null, {

View File

@ -1,5 +1,5 @@
<template> <template>
<LayoutHeader v-if="lead.data"> <LayoutHeader>
<header <header
class="relative flex h-10.5 items-center justify-between gap-2 py-2.5 pl-2" class="relative flex h-10.5 items-center justify-between gap-2 py-2.5 pl-2"
> >
@ -10,23 +10,21 @@
</Breadcrumbs> </Breadcrumbs>
<div class="absolute right-0"> <div class="absolute right-0">
<Dropdown <Dropdown
v-if="document.doc" v-if="doc"
:options=" :options="
statusOptions( statusOptions(
'lead', 'lead',
document.statuses?.length document.statuses?.length
? document.statuses ? document.statuses
: lead.data._customStatuses, : document._statuses,
triggerStatusChange, triggerStatusChange,
) )
" "
> >
<template #default="{ open }"> <template #default="{ open }">
<Button :label="document.doc.status"> <Button v-if="doc.status" :label="doc.status">
<template #prefix> <template #prefix>
<IndicatorIcon <IndicatorIcon :class="getLeadStatus(doc.status).color" />
:class="getLeadStatus(document.doc.status).color"
/>
</template> </template>
<template #suffix> <template #suffix>
<FeatherIcon <FeatherIcon
@ -41,18 +39,14 @@
</header> </header>
</LayoutHeader> </LayoutHeader>
<div <div
v-if="lead.data" v-if="doc.name"
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5" class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
> >
<AssignTo <AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
v-model="assignees.data"
:data="document.doc"
doctype="CRM Lead"
/>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<CustomActions <CustomActions
v-if="lead.data._customActions?.length" v-if="document._actions?.length"
:actions="lead.data._customActions" :actions="document._actions"
/> />
<CustomActions <CustomActions
v-if="document.actions?.length" v-if="document.actions?.length"
@ -65,14 +59,14 @@
/> />
</div> </div>
</div> </div>
<div v-if="lead?.data" class="flex h-full overflow-hidden"> <div v-if="doc.name" class="flex h-full overflow-hidden">
<Tabs as="div" v-model="tabIndex" :tabs="tabs" class="overflow-auto"> <Tabs as="div" v-model="tabIndex" :tabs="tabs" class="overflow-auto">
<TabList class="!px-3" /> <TabList class="!px-3" />
<TabPanel v-slot="{ tab }"> <TabPanel v-slot="{ tab }">
<div v-if="tab.name == 'Details'"> <div v-if="tab.name == 'Details'">
<SLASection <SLASection
v-if="lead.data.sla_status" v-if="doc.sla_status"
v-model="lead.data" v-model="doc"
@updateField="updateField" @updateField="updateField"
/> />
<div <div
@ -82,7 +76,7 @@
<SidePanelLayout <SidePanelLayout
:sections="sections.data" :sections="sections.data"
doctype="CRM Lead" doctype="CRM Lead"
:docname="lead.data.name" :docname="leadId"
@reload="sections.reload" @reload="sections.reload"
@afterFieldChange="reloadAssignees" @afterFieldChange="reloadAssignees"
/> />
@ -91,16 +85,21 @@
<Activities <Activities
v-else v-else
doctype="CRM Lead" doctype="CRM Lead"
:docname="leadId"
:tabs="tabs" :tabs="tabs"
v-model:reload="reload" v-model:reload="reload"
v-model:tabIndex="tabIndex" v-model:tabIndex="tabIndex"
v-model="lead"
@beforeSave="saveChanges" @beforeSave="saveChanges"
@afterSave="reloadAssignees" @afterSave="reloadAssignees"
/> />
</TabPanel> </TabPanel>
</Tabs> </Tabs>
</div> </div>
<ErrorPage
v-else-if="errorTitle"
:errorTitle="errorTitle"
:errorMessage="errorMessage"
/>
<Dialog <Dialog
v-model="showConvertToDealModal" v-model="showConvertToDealModal"
:options="{ :options="{
@ -167,8 +166,17 @@
</div> </div>
</template> </template>
</Dialog> </Dialog>
<DeleteLinkedDocModal
v-if="showDeleteLinkedDocModal"
v-model="showDeleteLinkedDocModal"
:doctype="'CRM Lead'"
:docname="leadId"
name="Leads"
/>
</template> </template>
<script setup> <script setup>
import DeleteLinkedDocModal from '@/components/DeleteLinkedDocModal.vue'
import ErrorPage from '@/components/ErrorPage.vue'
import Icon from '@/components/Icon.vue' import Icon from '@/components/Icon.vue'
import DetailsIcon from '@/components/Icons/DetailsIcon.vue' import DetailsIcon from '@/components/Icons/DetailsIcon.vue'
import ActivityIcon from '@/components/Icons/ActivityIcon.vue' import ActivityIcon from '@/components/Icons/ActivityIcon.vue'
@ -215,7 +223,7 @@ import {
usePageMeta, usePageMeta,
toast, toast,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, computed, onMounted, watch } from 'vue' import { ref, computed, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
const { brand } = getSettings() const { brand } = getSettings()
@ -232,71 +240,55 @@ const props = defineProps({
}, },
}) })
const lead = createResource({ const errorTitle = ref('')
url: 'crm.fcrm.doctype.crm_lead.api.get_lead', const errorMessage = ref('')
params: { name: props.leadId }, const showDeleteLinkedDocModal = ref(false)
cache: ['lead', props.leadId],
onSuccess: (data) => { const { triggerOnChange, assignees, document, scripts, error } = useDocument(
setupCustomizations(lead, { 'CRM Lead',
doc: data, props.leadId,
$dialog, )
$socket,
router, const doc = computed(() => document.doc || {})
toast,
updateField, watch(error, (err) => {
createToast: toast.create, if (err) {
deleteDoc: deleteLead, errorTitle.value = __(
resource: { err.exc_type == 'DoesNotExistError'
lead, ? 'Document not found'
sections, : 'Error occurred',
}, )
call, errorMessage.value = __(err.messages?.[0] || 'An error occurred')
}) } else {
}, errorTitle.value = ''
errorMessage.value = ''
}
}) })
onMounted(() => { watch(
if (lead.data) return () => document.doc,
lead.fetch() async (_doc) => {
}) if (scripts.data?.length) {
let s = await setupCustomizations(scripts.data, {
doc: _doc,
$dialog,
$socket,
router,
toast,
updateField,
createToast: toast.create,
deleteDoc: deleteLead,
call,
})
document._actions = s.actions || []
document._statuses = s.statuses || []
}
},
{ once: true },
)
const reload = ref(false) const reload = ref(false)
function updateLead(fieldname, value, callback) {
value = Array.isArray(fieldname) ? '' : value
if (!Array.isArray(fieldname) && validateRequired(fieldname, value)) return
createResource({
url: 'frappe.client.set_value',
params: {
doctype: 'CRM Lead',
name: props.leadId,
fieldname,
value,
},
auto: true,
onSuccess: () => {
lead.reload()
reload.value = true
toast.success(__('Lead updated successfully'))
callback?.()
},
onError: (err) => {
toast.error(__(err.messages?.[0] || 'Error updating lead'))
},
})
}
function validateRequired(fieldname, value) {
let meta = lead.data.fields_meta || {}
if (meta[fieldname]?.reqd && !value) {
toast.error(__('{0} is a required field', [meta[fieldname].label]))
return true
}
return false
}
const breadcrumbs = computed(() => { const breadcrumbs = computed(() => {
let items = [{ label: __('Leads'), route: { name: 'Leads' } }] let items = [{ label: __('Leads'), route: { name: 'Leads' } }]
@ -317,14 +309,14 @@ const breadcrumbs = computed(() => {
items.push({ items.push({
label: title.value, label: title.value,
route: { name: 'Lead', params: { leadId: lead.data.name } }, route: { name: 'Lead', params: { leadId: props.leadId } },
}) })
return items return items
}) })
const title = computed(() => { const title = computed(() => {
let t = doctypeMeta['CRM Lead']?.title_field || 'name' let t = doctypeMeta['CRM Lead']?.title_field || 'name'
return lead.data?.[t] || props.leadId return doc.value?.[t] || props.leadId
}) })
usePageMeta(() => { usePageMeta(() => {
@ -392,18 +384,8 @@ const tabs = computed(() => {
] ]
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true)) return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
}) })
const { tabIndex } = useActiveTabManager(tabs, 'lastLeadTab')
watch(tabs, (value) => { const { tabIndex } = useActiveTabManager(tabs, 'lastLeadTab')
if (value && route.params.tabName) {
let index = value.findIndex(
(tab) => tab.name.toLowerCase() === route.params.tabName.toLowerCase(),
)
if (index !== -1) {
tabIndex.value = index
}
}
})
const sections = createResource({ const sections = createResource({
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections', url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections',
@ -412,19 +394,31 @@ const sections = createResource({
auto: true, auto: true,
}) })
function updateField(name, value, callback) { function updateField(name, value) {
updateLead(name, value, () => { value = Array.isArray(name) ? '' : value
lead.data[name] = value let oldValues = Array.isArray(name) ? {} : doc.value[name]
callback?.()
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = value))
} else {
doc.value[name] = value
}
document.save.submit(null, {
onSuccess: () => (reload.value = true),
onError: (err) => {
if (Array.isArray(name)) {
name.forEach((field) => (doc.value[field] = oldValues[field]))
} else {
doc.value[name] = oldValues
}
toast.error(err.messages?.[0] || __('Error updating field'))
},
}) })
} }
async function deleteLead(name) { function deleteLead() {
await call('frappe.client.delete', { showDeleteLinkedDocModal.value = true
doctype: 'CRM Lead',
name,
})
router.push({ name: 'Leads' })
} }
// Convert to Deal // Convert to Deal
@ -455,7 +449,7 @@ async function convertToDeal() {
} }
let deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', { let deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', {
lead: lead.data.name, lead: props.leadId,
deal: {}, deal: {},
existing_contact: existingContact.value, existing_contact: existingContact.value,
existing_organization: existingOrganization.value, existing_organization: existingOrganization.value,
@ -471,11 +465,6 @@ async function convertToDeal() {
} }
} }
const { assignees, document, triggerOnChange } = useDocument(
'CRM Lead',
props.leadId,
)
async function triggerStatusChange(value) { async function triggerStatusChange(value) {
await triggerOnChange('status', value) await triggerOnChange('status', value)
document.save.submit() document.save.submit()

View File

@ -278,25 +278,18 @@ async function getFormScript(script, obj) {
return formScript || {} return formScript || {}
} }
export async function setupCustomizations(doc, obj) { export async function setupCustomizations(scripts, obj) {
if (!doc.data?._form_script) return [] if (!scripts) return []
let statuses = [] let statuses = []
let actions = [] let actions = []
if (Array.isArray(doc.data._form_script)) { if (Array.isArray(scripts)) {
for (let script of doc.data._form_script) { for (let s of scripts) {
let _script = await getFormScript(script, obj) let _script = await getFormScript(s.script, obj)
actions = actions.concat(_script?.actions || []) actions = actions.concat(_script?.actions || [])
statuses = statuses.concat(_script?.statuses || []) statuses = statuses.concat(_script?.statuses || [])
} }
} else {
let _script = await getFormScript(doc.data._form_script, obj)
actions = _script?.actions || []
statuses = _script?.statuses || []
} }
doc.data._customStatuses = statuses
doc.data._customActions = actions
return { statuses, actions } return { statuses, actions }
} }

View File

@ -18,29 +18,29 @@ echo "nvm use 18" >> ~/.bashrc
cd /workspace cd /workspace
bench init \ bench init \
--ignore-exist \ --ignore-exist \
--skip-redis-config-generation \ --skip-redis-config-generation \
frappe-bench frappe-bench
cd frappe-bench cd frappe-bench
# Use containers instead of localhost # Use containers instead of localhost
bench set-mariadb-host mariadb bench set-mariadb-host mariadb
bench set-redis-cache-host redis-cache:6379 bench set-redis-cache-host redis://redis-cache:6379
bench set-redis-queue-host redis-queue:6379 bench set-redis-queue-host redis://redis-queue:6379
bench set-redis-socketio-host redis-socketio:6379 bench set-redis-socketio-host redis://redis-socketio:6379
# Remove redis from Procfile # Remove redis from Procfile
sed -i '/redis/d' ./Procfile sed -i '/redis/d' ./Procfile
bench new-site dev.localhost \ bench new-site dev.localhost \
--mariadb-root-password 123 \ --mariadb-root-password 123 \
--admin-password admin \ --admin-password admin \
--no-mariadb-socket --no-mariadb-socket
bench --site dev.localhost set-config developer_mode 1 bench --site dev.localhost set-config developer_mode 1
bench --site dev.localhost clear-cache bench --site dev.localhost clear-cache
bench use dev.localhost bench use dev.localhost
bench get-app crm bench get-app crm
bench --site dev.localhost install-app crm bench --site dev.localhost install-app crm