From 8304d19e8b4b4a16f674627ab64f27aa2b9b4915 Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Mon, 24 Jun 2024 15:54:01 +0530 Subject: [PATCH 1/2] fix: creation of contact, customer, opportunity, quotation and prospect from lead --- erpnext/crm/doctype/lead/lead.js | 63 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index 8e568a2babe..40051e86024 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -28,11 +28,27 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller erpnext.toggle_naming_series(); if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) { - this.frm.add_custom_button(__("Customer"), this.make_customer, __("Create")); - this.frm.add_custom_button(__("Opportunity"), this.make_opportunity, __("Create")); - this.frm.add_custom_button(__("Quotation"), this.make_quotation, __("Create")); + this.frm.add_custom_button( + __("Customer"), + this.make_customer.bind(this), + __("Create") + ); + this.frm.add_custom_button( + __("Opportunity"), + this.make_opportunity.bind(this), + __("Create") + ); + this.frm.add_custom_button( + __("Quotation"), + this.make_quotation.bind(this), + __("Create") + ); if (!doc.__onload.linked_prospects.length) { - this.frm.add_custom_button(__("Prospect"), this.make_prospect, __("Create")); + this.frm.add_custom_button( + __("Prospect"), + this.make_prospect.bind(this), + __("Create") + ); this.frm.add_custom_button(__("Add to Prospect"), this.add_lead_to_prospect, __("Action")); } } @@ -95,20 +111,22 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller } async make_opportunity() { + const frm = this.frm; let existing_prospect = ( await frappe.db.get_value( "Prospect Lead", { - lead: this.frm.doc.name, + lead: frm.doc.name, }, "name", null, "Prospect" ) - ).message.name; + ).message?.name; + let fields = []; if (!existing_prospect) { - var fields = [ + fields.push( { label: "Create Prospect", fieldname: "create_prospect", @@ -119,21 +137,25 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller label: "Prospect Name", fieldname: "prospect_name", fieldtype: "Data", - default: this.frm.doc.company_name, + default: frm.doc.company_name, + reqd: 1, depends_on: "create_prospect", - }, - ]; + } + ); } + + await frm.reload_doc(); + let existing_contact = ( await frappe.db.get_value( "Contact", { - first_name: this.frm.doc.first_name || this.frm.doc.lead_name, - last_name: this.frm.doc.last_name, + first_name: frm.doc.first_name || frm.doc.lead_name, + last_name: frm.doc.last_name, }, "name" ) - ).message.name; + ).message?.name; if (!existing_contact) { fields.push({ @@ -144,24 +166,23 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller }); } - if (fields) { - var d = new frappe.ui.Dialog({ + if (fields.length) { + const d = new frappe.ui.Dialog({ title: __("Create Opportunity"), fields: fields, - primary_action: function () { - var data = d.get_values(); + primary_action: function(data) { frappe.call({ method: "create_prospect_and_contact", - doc: this.frm.doc, + doc: frm.doc, args: { data: data, }, freeze: true, - callback: function (r) { + callback: function(r) { if (!r.exc) { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_opportunity", - frm: this.frm, + frm: frm, }); } d.hide(); @@ -174,7 +195,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller } else { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_opportunity", - frm: this.frm, + frm: frm, }); } } From 5844897c34df7a727c7b14cdb67a136d33a70a18 Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Mon, 24 Jun 2024 16:03:39 +0530 Subject: [PATCH 2/2] fix: creation of contact, customer, opportunity, quotation and prospect from lead --prettier --- erpnext/crm/doctype/lead/lead.js | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index 40051e86024..28e0f5fdaee 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -28,27 +28,11 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller erpnext.toggle_naming_series(); if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) { - this.frm.add_custom_button( - __("Customer"), - this.make_customer.bind(this), - __("Create") - ); - this.frm.add_custom_button( - __("Opportunity"), - this.make_opportunity.bind(this), - __("Create") - ); - this.frm.add_custom_button( - __("Quotation"), - this.make_quotation.bind(this), - __("Create") - ); + this.frm.add_custom_button(__("Customer"), this.make_customer.bind(this), __("Create")); + this.frm.add_custom_button(__("Opportunity"), this.make_opportunity.bind(this), __("Create")); + this.frm.add_custom_button(__("Quotation"), this.make_quotation.bind(this), __("Create")); if (!doc.__onload.linked_prospects.length) { - this.frm.add_custom_button( - __("Prospect"), - this.make_prospect.bind(this), - __("Create") - ); + this.frm.add_custom_button(__("Prospect"), this.make_prospect.bind(this), __("Create")); this.frm.add_custom_button(__("Add to Prospect"), this.add_lead_to_prospect, __("Action")); } } @@ -170,7 +154,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller const d = new frappe.ui.Dialog({ title: __("Create Opportunity"), fields: fields, - primary_action: function(data) { + primary_action: function (data) { frappe.call({ method: "create_prospect_and_contact", doc: frm.doc, @@ -178,7 +162,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller data: data, }, freeze: true, - callback: function(r) { + callback: function (r) { if (!r.exc) { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_opportunity",