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] 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, - }); - } - }, -});