mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
Merge pull request #42014 from Nihantra-Patel/fix_lead_issue_dev
fix: creation of contact, customer, opportunity, quotation and prospect from lead
This commit is contained in:
@@ -28,11 +28,11 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
erpnext.toggle_naming_series();
|
erpnext.toggle_naming_series();
|
||||||
|
|
||||||
if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) {
|
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(__("Customer"), this.make_customer.bind(this), __("Create"));
|
||||||
this.frm.add_custom_button(__("Opportunity"), this.make_opportunity, __("Create"));
|
this.frm.add_custom_button(__("Opportunity"), this.make_opportunity.bind(this), __("Create"));
|
||||||
this.frm.add_custom_button(__("Quotation"), this.make_quotation, __("Create"));
|
this.frm.add_custom_button(__("Quotation"), this.make_quotation.bind(this), __("Create"));
|
||||||
if (!doc.__onload.linked_prospects.length) {
|
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"));
|
this.frm.add_custom_button(__("Add to Prospect"), this.add_lead_to_prospect, __("Action"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,20 +95,22 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
async make_opportunity() {
|
async make_opportunity() {
|
||||||
|
const frm = this.frm;
|
||||||
let existing_prospect = (
|
let existing_prospect = (
|
||||||
await frappe.db.get_value(
|
await frappe.db.get_value(
|
||||||
"Prospect Lead",
|
"Prospect Lead",
|
||||||
{
|
{
|
||||||
lead: this.frm.doc.name,
|
lead: frm.doc.name,
|
||||||
},
|
},
|
||||||
"name",
|
"name",
|
||||||
null,
|
null,
|
||||||
"Prospect"
|
"Prospect"
|
||||||
)
|
)
|
||||||
).message.name;
|
).message?.name;
|
||||||
|
|
||||||
|
let fields = [];
|
||||||
if (!existing_prospect) {
|
if (!existing_prospect) {
|
||||||
var fields = [
|
fields.push(
|
||||||
{
|
{
|
||||||
label: "Create Prospect",
|
label: "Create Prospect",
|
||||||
fieldname: "create_prospect",
|
fieldname: "create_prospect",
|
||||||
@@ -119,21 +121,25 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
label: "Prospect Name",
|
label: "Prospect Name",
|
||||||
fieldname: "prospect_name",
|
fieldname: "prospect_name",
|
||||||
fieldtype: "Data",
|
fieldtype: "Data",
|
||||||
default: this.frm.doc.company_name,
|
default: frm.doc.company_name,
|
||||||
|
reqd: 1,
|
||||||
depends_on: "create_prospect",
|
depends_on: "create_prospect",
|
||||||
},
|
}
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await frm.reload_doc();
|
||||||
|
|
||||||
let existing_contact = (
|
let existing_contact = (
|
||||||
await frappe.db.get_value(
|
await frappe.db.get_value(
|
||||||
"Contact",
|
"Contact",
|
||||||
{
|
{
|
||||||
first_name: this.frm.doc.first_name || this.frm.doc.lead_name,
|
first_name: frm.doc.first_name || frm.doc.lead_name,
|
||||||
last_name: this.frm.doc.last_name,
|
last_name: frm.doc.last_name,
|
||||||
},
|
},
|
||||||
"name"
|
"name"
|
||||||
)
|
)
|
||||||
).message.name;
|
).message?.name;
|
||||||
|
|
||||||
if (!existing_contact) {
|
if (!existing_contact) {
|
||||||
fields.push({
|
fields.push({
|
||||||
@@ -144,15 +150,14 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields) {
|
if (fields.length) {
|
||||||
var d = new frappe.ui.Dialog({
|
const d = new frappe.ui.Dialog({
|
||||||
title: __("Create Opportunity"),
|
title: __("Create Opportunity"),
|
||||||
fields: fields,
|
fields: fields,
|
||||||
primary_action: function () {
|
primary_action: function (data) {
|
||||||
var data = d.get_values();
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "create_prospect_and_contact",
|
method: "create_prospect_and_contact",
|
||||||
doc: this.frm.doc,
|
doc: frm.doc,
|
||||||
args: {
|
args: {
|
||||||
data: data,
|
data: data,
|
||||||
},
|
},
|
||||||
@@ -161,7 +166,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
if (!r.exc) {
|
if (!r.exc) {
|
||||||
frappe.model.open_mapped_doc({
|
frappe.model.open_mapped_doc({
|
||||||
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
|
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
|
||||||
frm: this.frm,
|
frm: frm,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
d.hide();
|
d.hide();
|
||||||
@@ -174,7 +179,7 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
} else {
|
} else {
|
||||||
frappe.model.open_mapped_doc({
|
frappe.model.open_mapped_doc({
|
||||||
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
|
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
|
||||||
frm: this.frm,
|
frm: frm,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user