feat: creation of prospect from lead

This commit is contained in:
Anupam 2021-08-24 15:50:15 +05:30
parent 4a529f8039
commit 797b19a14a
5 changed files with 57 additions and 39 deletions

View File

@ -39,6 +39,7 @@ 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"));
}
if (!this.frm.is_new()) {
@ -70,6 +71,13 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
})
}
make_prospect () {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_prospect",
frm: cur_frm
})
}
company_name () {
if (!this.frm.doc.lead_name) {
this.frm.set_value("lead_name", this.frm.doc.company_name);

View File

@ -190,16 +190,6 @@ class Lead(SellingController):
return contact
@frappe.whitelist()
def make_prospect(source_name, target_doc=None, leads=None):
print("``````````````````````````")
print(source_name)
print("``````````````````````````")
print(target_doc)
print("``````````````````````````")
print(leads)
print("``````````````````````````")
@frappe.whitelist()
def make_customer(source_name, target_doc=None):
return _make_customer(source_name, target_doc)
@ -272,6 +262,15 @@ def make_quotation(source_name, target_doc=None):
return target_doc
@frappe.whitelist()
def make_prospect(source_name, target_doc=None):
target_doc = get_mapped_doc("Lead", source_name,
{"Lead": {
"doctype": "Prospect",
}}, target_doc)
return target_doc
def _set_missing_values(source, target):
address = frappe.get_all('Dynamic Link', {
'link_doctype': source.doctype,

View File

@ -13,7 +13,7 @@ def get_data():
},
'transactions': [
{
'items': ['Opportunity', 'Quotation']
'items': ['Opportunity', 'Quotation', 'Prospect']
},
]
}

View File

@ -2,34 +2,26 @@ frappe.listview_settings['Lead'] = {
onload: function(listview) {
if (frappe.boot.user.can_create.includes("Prospect")) {
listview.page.add_action_item(__("Create Prospect"), function() {
let leads = listview.get_checked_items();
console.log(listview.get_checked_items());
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_prospect",
frm: cur_frm,
leads: leads
})
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;
// listview.call_for_selected_items(method, {"status": "Open"});
// let prospect_lead = []
// leads.forEach(lead => {
// prospect_lead.push({
// "lead": lead.name
// });
// });
// console.log("check");
// console.log(prospect_lead);
// frappe.new_doc("Prospect", {
// "company_name": leads[0].company_name,
// "industry": leads[0].industry,
// "market_segment": leads[0].market_segment,
// "territory": leads[0].territory,
// "no_of_employees": leads[0].no_of_employees,
// "fax": leads[0].fax,
// "website": leads[0].website,
// "prospect_owner": leads[0].lead_owner,
// "prospect_lead": prospect_lead
// });
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);
});
});
});
}
}

View File

@ -6,7 +6,26 @@ from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
class Prospect(Document):
pass
def validate(self):
self.link_with_lead_contact_and_address()
def link_with_lead_contact_and_address(self):
for row in self.prospect_lead:
links = frappe.get_all('Dynamic Link', filters={'link_doctype': 'Lead', 'link_name': row.lead}, fields=['parent', 'parenttype'])
for link in links:
linked_doc = frappe.get_doc(link['parenttype'], link['parent'])
exists = False
for d in linked_doc.get('links'):
if d.link_doctype == self.doctype and d.link_name == self.name:
exists = True
if not exists:
linked_doc.append('links', {
'link_doctype': self.doctype,
'link_name': self.name
})
linked_doc.save(ignore_permissions=True)
@frappe.whitelist()
def make_customer(source_name, target_doc=None):