diff --git a/frontend/src/data/document.js b/frontend/src/data/document.js index 514eb277..f79fc9fd 100644 --- a/frontend/src/data/document.js +++ b/frontend/src/data/document.js @@ -100,7 +100,15 @@ export function useDocument(doctype, docname) { async function triggerOnCreateLead() { const args = Array.from(arguments) const handler = async function () { - await this.on_create_lead(...args) + await this.on_create_lead?.(...args) + } + await trigger(handler) + } + + async function triggerConvertToDeal() { + const args = Array.from(arguments) + const handler = async function () { + await this.convert_to_deal?.(...args) } await trigger(handler) } @@ -139,5 +147,6 @@ export function useDocument(doctype, docname) { triggerOnRefresh, setupFormScript, triggerOnCreateLead, + triggerConvertToDeal, } } diff --git a/frontend/src/pages/Lead.vue b/frontend/src/pages/Lead.vue index 8499616e..65cf3f49 100644 --- a/frontend/src/pages/Lead.vue +++ b/frontend/src/pages/Lead.vue @@ -355,6 +355,7 @@ import { usersStore } from '@/stores/users' import { globalStore } from '@/stores/global' import { statusesStore } from '@/stores/statuses' import { getMeta } from '@/stores/meta' +import { useDocument } from '@/data/document' import { whatsappEnabled, callEnabled, @@ -614,6 +615,8 @@ const existingOrganizationChecked = ref(false) const existingContact = ref('') const existingOrganization = ref('') +const { triggerConvertToDeal } = useDocument('CRM Lead', props.leadId) + async function convertToDeal() { if (existingContactChecked.value && !existingContact.value) { toast.error(__('Please select an existing contact')) @@ -633,6 +636,12 @@ async function convertToDeal() { existingOrganization.value = '' } + await triggerConvertToDeal?.( + lead.data, + deal, + () => (showConvertToDealModal.value = false), + ) + let _deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', { lead: lead.data.name, deal,