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

feat(CRM): Prospect to group Leads #27102

Merged
merged 13 commits into from
Aug 27, 2021
61 changes: 55 additions & 6 deletions erpnext/crm/doctype/lead/lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
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(__("Prospect"), this.make_prospect, __("Create"));
this.frm.add_custom_button(__('Add to Prospect'), this.add_lead_to_prospect, __('Action'));
}

if (!this.frm.is_new()) {
Expand All @@ -49,27 +51,74 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
}
}

make_customer () {
add_lead_to_prospect (frm) {
frappe.prompt([
{
fieldname: 'prospect',
label: __('Prospect'),
fieldtype: 'Link',
options: 'Prospect',
reqd: 1
}
],
function(data) {
frappe.call({
method: 'erpnext.crm.doctype.lead.lead.add_lead_to_prospect',
args: {
'lead': frm.doc.name,
'prospect': data.prospect
},
callback: function(r) {
if (!r.exc) {
frm.reload_doc();
}
},
freeze: true,
freeze_message: __('...Adding Lead to Prospect')
});
}, __('Add Lead to Prospect'), __('Add'));
}

make_customer (frm) {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_customer",
frm: cur_frm
frm: frm
})
}

make_opportunity () {
make_opportunity (frm) {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
frm: cur_frm
frm: frm
})
}

make_quotation () {
make_quotation (frm) {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_quotation",
frm: cur_frm
frm: frm
})
}

make_prospect (frm) {
frappe.model.with_doctype("Prospect", function() {
let prospect = frappe.model.get_new_doc("Prospect");
prospect.company_name = frm.doc.company_name;
prospect.no_of_employees = frm.doc.no_of_employees;
prospect.industry = frm.doc.industry;
prospect.market_segment = frm.doc.market_segment;
prospect.territory = frm.doc.territory;
prospect.fax = frm.doc.fax;
prospect.website = frm.doc.website;
prospect.prospect_owner = frm.doc.lead_owner;

let lead_prospect_row = frappe.model.add_child(prospect, 'prospect_lead');
lead_prospect_row.lead = frm.doc.name;

frappe.set_route("Form", "Prospect", prospect.name);
});
}

company_name () {
if (!this.frm.doc.lead_name) {
this.frm.set_value("lead_name", this.frm.doc.company_name);
Expand Down
18 changes: 18 additions & 0 deletions erpnext/crm/doctype/lead/lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def validate_contact_date(self):

def on_update(self):
self.add_calendar_event()
self.update_prospects()

def before_insert(self):
self.contact_doc = self.create_contact()
Expand All @@ -89,6 +90,12 @@ def add_calendar_event(self, opts=None, force=False):
"description": ('Contact ' + cstr(self.lead_name)) + (self.contact_by and ('. By : ' + cstr(self.contact_by)) or '')
}, force)

def update_prospects(self):
prospects = frappe.get_all('Prospect Lead', filters={'lead': self.name}, fields=['parent'])
for row in prospects:
prospect = frappe.get_doc('Prospect', row.parent)
prospect.save(ignore_permissions=True)

def check_email_id_is_unique(self):
if self.email_id:
# validate email is unique
Expand Down Expand Up @@ -354,3 +361,14 @@ def daily_open_lead():
leads = frappe.get_all("Lead", filters = [["contact_date", "Between", [nowdate(), nowdate()]]])
for lead in leads:
frappe.db.set_value("Lead", lead.name, "status", "Open")

@frappe.whitelist()
def add_lead_to_prospect(lead, prospect):
prospect = frappe.get_doc('Prospect', prospect)
prospect.append('prospect_lead', {
'lead': lead
})
prospect.save(ignore_permissions=True)
frappe.msgprint(_('Lead {0} has been added to prospect {1}.').format(frappe.bold(lead), frappe.bold(prospect.name)),
title=_('Lead Added'), indicator='green')

2 changes: 1 addition & 1 deletion erpnext/crm/doctype/lead/lead_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_data():
},
'transactions': [
{
'items': ['Opportunity', 'Quotation']
'items': ['Opportunity', 'Quotation', 'Prospect']
},
]
}
28 changes: 28 additions & 0 deletions erpnext/crm/doctype/lead/lead_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
frappe.listview_settings['Lead'] = {
onload: function(listview) {
if (frappe.boot.user.can_create.includes("Prospect")) {
listview.page.add_action_item(__("Create Prospect"), function() {
frappe.model.with_doctype("Prospect", function() {
let prospect = frappe.model.get_new_doc("Prospect");
let leads = listview.get_checked_items();
frappe.db.get_value("Lead", leads[0].name, ["company_name", "no_of_employees", "industry", "market_segment", "territory", "fax", "website", "lead_owner"], (r) => {
prospect.company_name = r.company_name;
prospect.no_of_employees = r.no_of_employees;
prospect.industry = r.industry;
prospect.market_segment = r.market_segment;
prospect.territory = r.territory;
prospect.fax = r.fax;
prospect.website = r.website;
prospect.prospect_owner = r.lead_owner;

leads.forEach(function(lead) {
let lead_prospect_row = frappe.model.add_child(prospect, 'prospect_lead');
lead_prospect_row.lead = lead.name;
});
frappe.set_route("Form", "Prospect", prospect.name);
});
});
});
}
}
};
4 changes: 2 additions & 2 deletions erpnext/crm/doctype/opportunity/opportunity.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ frappe.ui.form.on("Opportunity", {
frm.custom_make_buttons = {
'Quotation': 'Quotation',
'Supplier Quotation': 'Supplier Quotation'
},
};

frm.set_query("opportunity_from", function() {
return{
"filters": {
"name": ["in", ["Customer", "Lead"]],
"name": ["in", ["Customer", "Lead", "Prospect"]],
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion erpnext/crm/doctype/opportunity/opportunity.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
"icon": "fa fa-info-sign",
"idx": 195,
"links": [],
"modified": "2021-06-04 10:11:22.831139",
"modified": "2021-08-25 10:28:24.923543",
"modified_by": "Administrator",
"module": "CRM",
"name": "Opportunity",
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions erpnext/crm/doctype/prospect/prospect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

frappe.ui.form.on('Prospect', {
refresh (frm) {
if (!frm.is_new() && frappe.boot.user.can_create.includes("Customer")) {
frm.add_custom_button(__("Customer"), function() {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.prospect.prospect.make_customer",
frm: frm
});
}, __("Create"));
}
if (!frm.is_new() && frappe.boot.user.can_create.includes("Opportunity")) {
frm.add_custom_button(__("Opportunity"), function() {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.prospect.prospect.make_opportunity",
frm: frm
});
}, __("Create"));
}

if (!frm.is_new()) {
frappe.contacts.render_address_and_contact(frm);
} else {
frappe.contacts.clear_address_and_contact(frm);
}
}
});
Loading