From ef10c4ea4f969a0c6ef12f3733324ae43e689675 Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Mon, 24 Jun 2024 15:54:01 +0530 Subject: [PATCH 1/3] fix: creation of contact, customer, opportunity, quotation and prospect from lead (cherry picked from commit 8304d19e8b4b4a16f674627ab64f27aa2b9b4915) # Conflicts: # erpnext/crm/doctype/lead/lead.js --- erpnext/crm/doctype/lead/lead.js | 117 ++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index 609eab7f9a2..448aa858a4c 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -28,6 +28,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller erpnext.toggle_naming_series(); if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) { +<<<<<<< HEAD this.frm.add_custom_button(__("Customer"), this.make_customer, __("Create")); this.frm.add_custom_button( __("Opportunity"), @@ -37,8 +38,29 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller __("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") + ); +>>>>>>> 8304d19e8b (fix: creation of contact, customer, opportunity, quotation and prospect from lead) 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")); } } @@ -100,6 +122,99 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller }); } +<<<<<<< HEAD +======= + async make_opportunity() { + const frm = this.frm; + let existing_prospect = ( + await frappe.db.get_value( + "Prospect Lead", + { + lead: frm.doc.name, + }, + "name", + null, + "Prospect" + ) + ).message?.name; + + let fields = []; + if (!existing_prospect) { + fields.push( + { + label: "Create Prospect", + fieldname: "create_prospect", + fieldtype: "Check", + default: 1, + }, + { + label: "Prospect Name", + fieldname: "prospect_name", + fieldtype: "Data", + 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: frm.doc.first_name || frm.doc.lead_name, + last_name: frm.doc.last_name, + }, + "name" + ) + ).message?.name; + + if (!existing_contact) { + fields.push({ + label: "Create Contact", + fieldname: "create_contact", + fieldtype: "Check", + default: "1", + }); + } + + if (fields.length) { + const d = new frappe.ui.Dialog({ + title: __("Create Opportunity"), + fields: fields, + primary_action: function(data) { + frappe.call({ + method: "create_prospect_and_contact", + doc: frm.doc, + args: { + data: data, + }, + freeze: true, + callback: function(r) { + if (!r.exc) { + frappe.model.open_mapped_doc({ + method: "erpnext.crm.doctype.lead.lead.make_opportunity", + frm: frm, + }); + } + d.hide(); + }, + }); + }, + primary_action_label: __("Create"), + }); + d.show(); + } else { + frappe.model.open_mapped_doc({ + method: "erpnext.crm.doctype.lead.lead.make_opportunity", + frm: frm, + }); + } + } + +>>>>>>> 8304d19e8b (fix: creation of contact, customer, opportunity, quotation and prospect from lead) make_prospect() { frappe.model.with_doctype("Prospect", function () { let prospect = frappe.model.get_new_doc("Prospect"); From 5a2a404a50ebb40507abbd34dc6a1975db4940ca Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Mon, 24 Jun 2024 16:03:39 +0530 Subject: [PATCH 2/3] fix: creation of contact, customer, opportunity, quotation and prospect from lead --prettier (cherry picked from commit 5844897c34df7a727c7b14cdb67a136d33a70a18) # Conflicts: # erpnext/crm/doctype/lead/lead.js --- erpnext/crm/doctype/lead/lead.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index 448aa858a4c..f27187924af 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -28,6 +28,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller erpnext.toggle_naming_series(); if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) { +<<<<<<< HEAD <<<<<<< HEAD this.frm.add_custom_button(__("Customer"), this.make_customer, __("Create")); this.frm.add_custom_button( @@ -55,12 +56,13 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller __("Create") ); >>>>>>> 8304d19e8b (fix: creation of contact, customer, opportunity, quotation and prospect from lead) +======= + 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")); +>>>>>>> 5844897c34 (fix: creation of contact, customer, opportunity, quotation and prospect from lead --prettier) 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")); } } @@ -184,7 +186,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, @@ -192,7 +194,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", From 85d74050e1b35126e4c9b2d4a7cb1bc3c27ae835 Mon Sep 17 00:00:00 2001 From: "Nihantra C. Patel" <141945075+Nihantra-Patel@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:51:04 +0530 Subject: [PATCH 3/3] fix: #42014 --resolve conflicts --- erpnext/crm/doctype/lead/lead.js | 160 +++++-------------------------- 1 file changed, 23 insertions(+), 137 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index f27187924af..e50cf9e4dd0 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -28,42 +28,18 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller erpnext.toggle_naming_series(); if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) { -<<<<<<< HEAD -<<<<<<< HEAD - this.frm.add_custom_button(__("Customer"), this.make_customer, __("Create")); - this.frm.add_custom_button( - __("Opportunity"), - function () { - me.frm.trigger("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") - ); ->>>>>>> 8304d19e8b (fix: creation of contact, customer, opportunity, quotation and prospect from lead) -======= 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")); ->>>>>>> 5844897c34 (fix: creation of contact, customer, opportunity, quotation and prospect from lead --prettier) if (!doc.__onload.linked_prospects.length) { 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")); + this.frm.add_custom_button( + __("Add to Prospect"), + () => { + this.add_lead_to_prospect(this.frm); + }, + __("Action") + ); } } @@ -77,8 +53,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller this.show_activities(); } - add_lead_to_prospect() { - let me = this; + add_lead_to_prospect(frm) { frappe.prompt( [ { @@ -93,12 +68,12 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller frappe.call({ method: "erpnext.crm.doctype.lead.lead.add_lead_to_prospect", args: { - lead: me.frm.doc.name, + lead: frm.doc.name, prospect: data.prospect, }, callback: function (r) { if (!r.exc) { - me.frm.reload_doc(); + frm.reload_doc(); } }, freeze: true, @@ -113,19 +88,17 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller make_customer() { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_customer", - frm: cur_frm, + frm: this.frm, }); } make_quotation() { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_quotation", - frm: cur_frm, + frm: this.frm, }); } -<<<<<<< HEAD -======= async make_opportunity() { const frm = this.frm; let existing_prospect = ( @@ -216,22 +189,22 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller } } ->>>>>>> 8304d19e8b (fix: creation of contact, customer, opportunity, quotation and prospect from lead) make_prospect() { + const me = this; frappe.model.with_doctype("Prospect", function () { let prospect = frappe.model.get_new_doc("Prospect"); - prospect.company_name = cur_frm.doc.company_name; - prospect.no_of_employees = cur_frm.doc.no_of_employees; - prospect.industry = cur_frm.doc.industry; - prospect.market_segment = cur_frm.doc.market_segment; - prospect.territory = cur_frm.doc.territory; - prospect.fax = cur_frm.doc.fax; - prospect.website = cur_frm.doc.website; - prospect.prospect_owner = cur_frm.doc.lead_owner; - prospect.notes = cur_frm.doc.notes; + prospect.company_name = me.frm.doc.company_name; + prospect.no_of_employees = me.frm.doc.no_of_employees; + prospect.industry = me.frm.doc.industry; + prospect.market_segment = me.frm.doc.market_segment; + prospect.territory = me.frm.doc.territory; + prospect.fax = me.frm.doc.fax; + prospect.website = me.frm.doc.website; + prospect.prospect_owner = me.frm.doc.lead_owner; + prospect.notes = me.frm.doc.notes; let leads_row = frappe.model.add_child(prospect, "leads"); - leads_row.lead = cur_frm.doc.name; + leads_row.lead = me.frm.doc.name; frappe.set_route("Form", "Prospect", prospect.name); }); @@ -267,90 +240,3 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller }; extend_cscript(cur_frm.cscript, new erpnext.LeadController({ frm: cur_frm })); - -frappe.ui.form.on("Lead", { - make_opportunity: async function (frm) { - let existing_prospect = ( - await frappe.db.get_value( - "Prospect Lead", - { - lead: frm.doc.name, - }, - "name", - null, - "Prospect" - ) - ).message.name; - - if (!existing_prospect) { - var fields = [ - { - label: "Create Prospect", - fieldname: "create_prospect", - fieldtype: "Check", - default: 1, - }, - { - label: "Prospect Name", - fieldname: "prospect_name", - fieldtype: "Data", - default: frm.doc.company_name, - depends_on: "create_prospect", - }, - ]; - } - let existing_contact = ( - await frappe.db.get_value( - "Contact", - { - first_name: frm.doc.first_name || frm.doc.lead_name, - last_name: frm.doc.last_name, - }, - "name" - ) - ).message.name; - - if (!existing_contact) { - fields.push({ - label: "Create Contact", - fieldname: "create_contact", - fieldtype: "Check", - default: "1", - }); - } - - if (fields) { - var d = new frappe.ui.Dialog({ - title: __("Create Opportunity"), - fields: fields, - primary_action: function () { - var data = d.get_values(); - frappe.call({ - method: "create_prospect_and_contact", - doc: frm.doc, - args: { - data: data, - }, - freeze: true, - callback: function (r) { - if (!r.exc) { - frappe.model.open_mapped_doc({ - method: "erpnext.crm.doctype.lead.lead.make_opportunity", - frm: frm, - }); - } - d.hide(); - }, - }); - }, - primary_action_label: __("Create"), - }); - d.show(); - } else { - frappe.model.open_mapped_doc({ - method: "erpnext.crm.doctype.lead.lead.make_opportunity", - frm: frm, - }); - } - }, -});