mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 13:49:13 +00:00
feat: creation of prospect from lead
This commit is contained in:
@@ -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(__("Customer"), this.make_customer, __("Create"));
|
||||||
this.frm.add_custom_button(__("Opportunity"), this.make_opportunity, __("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(__("Quotation"), this.make_quotation, __("Create"));
|
||||||
|
this.frm.add_custom_button(__("Prospect"), this.make_prospect, __("Create"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.frm.is_new()) {
|
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 () {
|
company_name () {
|
||||||
if (!this.frm.doc.lead_name) {
|
if (!this.frm.doc.lead_name) {
|
||||||
this.frm.set_value("lead_name", this.frm.doc.company_name);
|
this.frm.set_value("lead_name", this.frm.doc.company_name);
|
||||||
|
|||||||
@@ -190,16 +190,6 @@ class Lead(SellingController):
|
|||||||
|
|
||||||
return contact
|
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()
|
@frappe.whitelist()
|
||||||
def make_customer(source_name, target_doc=None):
|
def make_customer(source_name, target_doc=None):
|
||||||
return _make_customer(source_name, target_doc)
|
return _make_customer(source_name, target_doc)
|
||||||
@@ -272,6 +262,15 @@ def make_quotation(source_name, target_doc=None):
|
|||||||
|
|
||||||
return target_doc
|
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):
|
def _set_missing_values(source, target):
|
||||||
address = frappe.get_all('Dynamic Link', {
|
address = frappe.get_all('Dynamic Link', {
|
||||||
'link_doctype': source.doctype,
|
'link_doctype': source.doctype,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ def get_data():
|
|||||||
},
|
},
|
||||||
'transactions': [
|
'transactions': [
|
||||||
{
|
{
|
||||||
'items': ['Opportunity', 'Quotation']
|
'items': ['Opportunity', 'Quotation', 'Prospect']
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -2,34 +2,26 @@ frappe.listview_settings['Lead'] = {
|
|||||||
onload: function(listview) {
|
onload: function(listview) {
|
||||||
if (frappe.boot.user.can_create.includes("Prospect")) {
|
if (frappe.boot.user.can_create.includes("Prospect")) {
|
||||||
listview.page.add_action_item(__("Create Prospect"), function() {
|
listview.page.add_action_item(__("Create Prospect"), function() {
|
||||||
let leads = listview.get_checked_items();
|
frappe.model.with_doctype("Prospect", function() {
|
||||||
console.log(listview.get_checked_items());
|
let prospect = frappe.model.get_new_doc("Prospect");
|
||||||
frappe.model.open_mapped_doc({
|
let leads = listview.get_checked_items();
|
||||||
method: "erpnext.crm.doctype.lead.lead.make_prospect",
|
frappe.db.get_value("Lead", leads[0].name, ["company_name", "no_of_employees", "industry", "market_segment", "territory", "fax", "website", "lead_owner"], (r) => {
|
||||||
frm: cur_frm,
|
prospect.company_name = r.company_name;
|
||||||
leads: leads
|
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"});
|
leads.forEach(function(lead) {
|
||||||
// let prospect_lead = []
|
let lead_prospect_row = frappe.model.add_child(prospect, 'prospect_lead');
|
||||||
// leads.forEach(lead => {
|
lead_prospect_row.lead = lead.name;
|
||||||
// prospect_lead.push({
|
});
|
||||||
// "lead": lead.name
|
frappe.set_route("Form", "Prospect", prospect.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
|
|
||||||
// });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,26 @@ from frappe.model.document import Document
|
|||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
|
|
||||||
class Prospect(Document):
|
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()
|
@frappe.whitelist()
|
||||||
def make_customer(source_name, target_doc=None):
|
def make_customer(source_name, target_doc=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user