feat: intercept convert to deal via form script

This commit is contained in:
Shariq Ansari 2025-05-26 14:30:15 +05:30
parent 8798103e7e
commit bfdd3273fe
2 changed files with 19 additions and 1 deletions

View File

@ -100,7 +100,15 @@ export function useDocument(doctype, docname) {
async function triggerOnCreateLead() { async function triggerOnCreateLead() {
const args = Array.from(arguments) const args = Array.from(arguments)
const handler = async function () { 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) await trigger(handler)
} }
@ -139,5 +147,6 @@ export function useDocument(doctype, docname) {
triggerOnRefresh, triggerOnRefresh,
setupFormScript, setupFormScript,
triggerOnCreateLead, triggerOnCreateLead,
triggerConvertToDeal,
} }
} }

View File

@ -355,6 +355,7 @@ import { usersStore } from '@/stores/users'
import { globalStore } from '@/stores/global' import { globalStore } from '@/stores/global'
import { statusesStore } from '@/stores/statuses' import { statusesStore } from '@/stores/statuses'
import { getMeta } from '@/stores/meta' import { getMeta } from '@/stores/meta'
import { useDocument } from '@/data/document'
import { import {
whatsappEnabled, whatsappEnabled,
callEnabled, callEnabled,
@ -614,6 +615,8 @@ const existingOrganizationChecked = ref(false)
const existingContact = ref('') const existingContact = ref('')
const existingOrganization = ref('') const existingOrganization = ref('')
const { triggerConvertToDeal } = useDocument('CRM Lead', props.leadId)
async function convertToDeal() { async function convertToDeal() {
if (existingContactChecked.value && !existingContact.value) { if (existingContactChecked.value && !existingContact.value) {
toast.error(__('Please select an existing contact')) toast.error(__('Please select an existing contact'))
@ -633,6 +636,12 @@ async function convertToDeal() {
existingOrganization.value = '' existingOrganization.value = ''
} }
await triggerConvertToDeal?.(
lead.data,
deal,
() => (showConvertToDealModal.value = false),
)
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: lead.data.name,
deal, deal,