Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: creation of contact, customer, opportunity, quotation and prospect from lead (backport #42014) #43296

Open
wants to merge 2 commits into
base: version-15-hotfix
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 118 additions & 1 deletion erpnext/crm/doctype/lead/lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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"),
Expand All @@ -37,8 +39,30 @@ 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)
=======
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, __("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"));
}
}
Expand Down Expand Up @@ -100,6 +124,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");
Expand Down
Loading