fix: after converting to deal add contact & deal owner
This commit is contained in:
parent
4371a27484
commit
d297f045c5
@ -15,9 +15,6 @@ class CRMLead(Document):
|
|||||||
self.set_title()
|
self.set_title()
|
||||||
self.validate_email()
|
self.validate_email()
|
||||||
|
|
||||||
if self.has_value_changed('converted') and self.converted:
|
|
||||||
self.create_contact()
|
|
||||||
|
|
||||||
def set_full_name(self):
|
def set_full_name(self):
|
||||||
if self.first_name:
|
if self.first_name:
|
||||||
self.lead_name = " ".join(
|
self.lead_name = " ".join(
|
||||||
@ -83,7 +80,7 @@ class CRMLead(Document):
|
|||||||
contact.insert(ignore_permissions=True)
|
contact.insert(ignore_permissions=True)
|
||||||
contact.reload() # load changes by hooks on contact
|
contact.reload() # load changes by hooks on contact
|
||||||
|
|
||||||
return contact
|
return contact.name
|
||||||
|
|
||||||
def contact_exists(self):
|
def contact_exists(self):
|
||||||
email_exist = frappe.db.exists("Contact Email", {"email_id": self.email})
|
email_exist = frappe.db.exists("Contact Email", {"email_id": self.email})
|
||||||
@ -105,6 +102,19 @@ class CRMLead(Document):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def create_deal(self, contact):
|
||||||
|
deal = frappe.new_doc("CRM Deal")
|
||||||
|
deal.update(
|
||||||
|
{
|
||||||
|
"lead": self.name,
|
||||||
|
"organization": self.organization,
|
||||||
|
"deal_owner": self.lead_owner,
|
||||||
|
"contacts": [{"contact": contact}],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
deal.insert(ignore_permissions=True)
|
||||||
|
return deal.name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sort_options():
|
def sort_options():
|
||||||
return [
|
return [
|
||||||
@ -118,4 +128,17 @@ class CRMLead(Document):
|
|||||||
{ "label": 'Last Name', "value": 'last_name' },
|
{ "label": 'Last Name', "value": 'last_name' },
|
||||||
{ "label": 'Email', "value": 'email' },
|
{ "label": 'Email', "value": 'email' },
|
||||||
{ "label": 'Mobile no', "value": 'mobile_no' },
|
{ "label": 'Mobile no', "value": 'mobile_no' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def convert_to_deal(lead):
|
||||||
|
if not frappe.has_permission("CRM Lead", "write", lead):
|
||||||
|
frappe.throw(_("Not allowed to convert Lead to Deal"), frappe.PermissionError)
|
||||||
|
|
||||||
|
lead = frappe.get_cached_doc("CRM Lead", lead)
|
||||||
|
lead.status = "Qualified"
|
||||||
|
lead.converted = 1
|
||||||
|
contact = lead.create_contact()
|
||||||
|
deal = lead.create_deal(contact)
|
||||||
|
lead.save()
|
||||||
|
return deal
|
||||||
@ -379,7 +379,6 @@ function updateLead(fieldname, value, callback) {
|
|||||||
auto: true,
|
auto: true,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
lead.reload()
|
lead.reload()
|
||||||
contacts.reload()
|
|
||||||
reload.value = true
|
reload.value = true
|
||||||
createToast({
|
createToast({
|
||||||
title: 'Lead updated',
|
title: 'Lead updated',
|
||||||
@ -555,26 +554,13 @@ const organization = computed(() => {
|
|||||||
return getOrganization(lead.data.organization)
|
return getOrganization(lead.data.organization)
|
||||||
})
|
})
|
||||||
|
|
||||||
function convertToDeal() {
|
async function convertToDeal() {
|
||||||
updateLead({ status: 'Qualified', converted: 1 }, '', () => {
|
let deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', {
|
||||||
lead.data.status = 'Qualified'
|
lead: lead.data.name,
|
||||||
lead.data.converted = 1
|
|
||||||
createDeal(lead.data)
|
|
||||||
})
|
})
|
||||||
}
|
if (deal) {
|
||||||
|
await contacts.reload()
|
||||||
async function createDeal(lead) {
|
router.push({ name: 'Deal', params: { dealId: deal } })
|
||||||
let d = await call('frappe.client.insert', {
|
|
||||||
doc: {
|
|
||||||
doctype: 'CRM Deal',
|
|
||||||
organization: lead.organization,
|
|
||||||
email: lead.email,
|
|
||||||
mobile_no: lead.mobile_no,
|
|
||||||
lead: lead.name,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (d.name) {
|
|
||||||
router.push({ name: 'Deal', params: { dealId: d.name } })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user