refactor: lead
This commit is contained in:
parent
80077d215f
commit
dc448c2f51
@ -68,11 +68,6 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
organization_lead () {
|
|
||||||
this.frm.toggle_reqd("lead_name", !this.frm.doc.organization_lead);
|
|
||||||
this.frm.toggle_reqd("company_name", this.frm.doc.organization_lead);
|
|
||||||
}
|
|
||||||
|
|
||||||
company_name () {
|
company_name () {
|
||||||
if (this.frm.doc.organization_lead && !this.frm.doc.lead_name) {
|
if (this.frm.doc.organization_lead && !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);
|
||||||
|
|||||||
@ -9,30 +9,32 @@
|
|||||||
"email_append_to": 1,
|
"email_append_to": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"organization_lead",
|
|
||||||
"lead_details",
|
"lead_details",
|
||||||
"naming_series",
|
"naming_series",
|
||||||
"lead_name",
|
|
||||||
"company_name",
|
|
||||||
"email_id",
|
|
||||||
"col_break123",
|
|
||||||
"lead_owner",
|
|
||||||
"status",
|
|
||||||
"salutation",
|
"salutation",
|
||||||
|
"first_name",
|
||||||
|
"middle_name",
|
||||||
|
"last_name",
|
||||||
|
"lead_name",
|
||||||
|
"email_id",
|
||||||
|
"mobile_no",
|
||||||
|
"phone",
|
||||||
|
"col_break123",
|
||||||
|
"status",
|
||||||
|
"company_name",
|
||||||
"designation",
|
"designation",
|
||||||
"gender",
|
"gender",
|
||||||
"source",
|
"additional_information_section",
|
||||||
"customer",
|
"no_of_employees",
|
||||||
"campaign_name",
|
"industry",
|
||||||
"image",
|
"market_segment",
|
||||||
"section_break_12",
|
"type",
|
||||||
"contact_by",
|
"request_type",
|
||||||
"column_break_14",
|
"column_break_22",
|
||||||
"contact_date",
|
"whatsapp_no",
|
||||||
"ends_on",
|
"fax",
|
||||||
"notes_section",
|
"website",
|
||||||
"notes",
|
"address_section",
|
||||||
"address_info",
|
|
||||||
"address_html",
|
"address_html",
|
||||||
"address_type",
|
"address_type",
|
||||||
"address_title",
|
"address_title",
|
||||||
@ -45,35 +47,33 @@
|
|||||||
"state",
|
"state",
|
||||||
"country",
|
"country",
|
||||||
"pincode",
|
"pincode",
|
||||||
"contact_section",
|
"section_break_12",
|
||||||
"phone",
|
"lead_owner",
|
||||||
"mobile_no",
|
"ends_on",
|
||||||
"fax",
|
"column_break_14",
|
||||||
"website",
|
"contact_by",
|
||||||
"more_info",
|
"contact_date",
|
||||||
"type",
|
"lead_source_details_section",
|
||||||
"market_segment",
|
|
||||||
"industry",
|
|
||||||
"request_type",
|
|
||||||
"column_break3",
|
|
||||||
"company",
|
"company",
|
||||||
"territory",
|
"territory",
|
||||||
"language",
|
"language",
|
||||||
|
"column_break_50",
|
||||||
|
"source",
|
||||||
|
"campaign_name",
|
||||||
"unsubscribed",
|
"unsubscribed",
|
||||||
"blog_subscriber",
|
"blog_subscriber",
|
||||||
|
"notes_section",
|
||||||
|
"notes",
|
||||||
|
"other_information_section",
|
||||||
|
"customer",
|
||||||
|
"image",
|
||||||
"title"
|
"title"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
|
||||||
"default": "0",
|
|
||||||
"fieldname": "organization_lead",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"label": "Lead is an Organization",
|
|
||||||
"set_only_once": 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "lead_details",
|
"fieldname": "lead_details",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Lead Details",
|
||||||
"options": "fa fa-user"
|
"options": "fa fa-user"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -90,7 +90,8 @@
|
|||||||
"fieldname": "lead_name",
|
"fieldname": "lead_name",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_global_search": 1,
|
"in_global_search": 1,
|
||||||
"label": "Person Name",
|
"label": "Full Name",
|
||||||
|
"mandatory_depends_on": "eval: !(doc.company_name)",
|
||||||
"oldfieldname": "lead_name",
|
"oldfieldname": "lead_name",
|
||||||
"oldfieldtype": "Data",
|
"oldfieldtype": "Data",
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
@ -99,7 +100,9 @@
|
|||||||
"fieldname": "company_name",
|
"fieldname": "company_name",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 1,
|
||||||
"label": "Organization Name",
|
"label": "Organization Name",
|
||||||
|
"mandatory_depends_on": "eval: !(doc.lead_name)",
|
||||||
"oldfieldname": "company_name",
|
"oldfieldname": "company_name",
|
||||||
"oldfieldtype": "Data"
|
"oldfieldtype": "Data"
|
||||||
},
|
},
|
||||||
@ -121,7 +124,6 @@
|
|||||||
"default": "__user",
|
"default": "__user",
|
||||||
"fieldname": "lead_owner",
|
"fieldname": "lead_owner",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Lead Owner",
|
"label": "Lead Owner",
|
||||||
"oldfieldname": "lead_owner",
|
"oldfieldname": "lead_owner",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
@ -241,46 +243,39 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"description": "Home, Work, etc.",
|
"description": "Home, Work, etc.",
|
||||||
"fieldname": "address_title",
|
"fieldname": "address_title",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Address Title"
|
"label": "Address Title"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "address_line1",
|
"fieldname": "address_line1",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Address Line 1",
|
"label": "Address Line 1",
|
||||||
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
|
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "address_line2",
|
"fieldname": "address_line2",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Address Line 2"
|
"label": "Address Line 2"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "city",
|
"fieldname": "city",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "City/Town",
|
"label": "City/Town",
|
||||||
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
|
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "county",
|
"fieldname": "county",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "County"
|
"label": "County"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "state",
|
"fieldname": "state",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "State"
|
"label": "State"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "country",
|
"fieldname": "country",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Country",
|
"label": "Country",
|
||||||
@ -288,7 +283,7 @@
|
|||||||
"options": "Country"
|
"options": "Country"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: doc.__islocal",
|
"collapsible_depends_on": "eval: doc.__islocal",
|
||||||
"fieldname": "pincode",
|
"fieldname": "pincode",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Postal Code"
|
"label": "Postal Code"
|
||||||
@ -329,14 +324,6 @@
|
|||||||
"oldfieldname": "fax",
|
"oldfieldname": "fax",
|
||||||
"oldfieldtype": "Data"
|
"oldfieldtype": "Data"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"collapsible": 1,
|
|
||||||
"fieldname": "more_info",
|
|
||||||
"fieldtype": "Section Break",
|
|
||||||
"label": "More Information",
|
|
||||||
"oldfieldtype": "Section Break",
|
|
||||||
"options": "fa fa-file-text"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "type",
|
"fieldname": "type",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
@ -369,12 +356,6 @@
|
|||||||
"oldfieldtype": "Select",
|
"oldfieldtype": "Select",
|
||||||
"options": "\nProduct Enquiry\nRequest for Information\nSuggestions\nOther"
|
"options": "\nProduct Enquiry\nRequest for Information\nSuggestions\nOther"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "column_break3",
|
|
||||||
"fieldtype": "Column Break",
|
|
||||||
"oldfieldtype": "Column Break",
|
|
||||||
"width": "50%"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "company",
|
"fieldname": "company",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
@ -389,11 +370,14 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Website",
|
"label": "Website",
|
||||||
"oldfieldname": "website",
|
"oldfieldname": "website",
|
||||||
"oldfieldtype": "Data"
|
"oldfieldtype": "Data",
|
||||||
|
"options": "URL"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "territory",
|
"fieldname": "territory",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 1,
|
||||||
"label": "Territory",
|
"label": "Territory",
|
||||||
"oldfieldname": "territory",
|
"oldfieldname": "territory",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
@ -422,28 +406,13 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "designation",
|
"fieldname": "designation",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 1,
|
||||||
"label": "Designation",
|
"label": "Designation",
|
||||||
"options": "Designation"
|
"options": "Designation"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"collapsible": 1,
|
|
||||||
"collapsible_depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "address_info",
|
|
||||||
"fieldtype": "Section Break",
|
|
||||||
"label": "Address & Contact",
|
|
||||||
"oldfieldtype": "Column Break",
|
|
||||||
"options": "fa fa-map-marker"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"collapsible": 1,
|
|
||||||
"collapsible_depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "contact_section",
|
|
||||||
"fieldtype": "Section Break",
|
|
||||||
"label": "Contact"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"default": "Billing",
|
"default": "Billing",
|
||||||
"depends_on": "eval: doc.__islocal",
|
|
||||||
"fieldname": "address_type",
|
"fieldname": "address_type",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Address Type",
|
"label": "Address Type",
|
||||||
@ -454,13 +423,70 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Print Language",
|
"label": "Print Language",
|
||||||
"options": "Language"
|
"options": "Language"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "first_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "First Name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "middle_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Middle Name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "last_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Last Name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collapsible": 1,
|
||||||
|
"fieldname": "additional_information_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Additional Information"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "no_of_employees",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "No. of Employees"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_22",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "whatsapp_no",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "WhatsApp No.",
|
||||||
|
"options": "Phone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collapsible": 1,
|
||||||
|
"depends_on": "eval:!doc.__islocal",
|
||||||
|
"fieldname": "address_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "lead_source_details_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Lead Source Details"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_50",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "other_information_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Other Information"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-user",
|
"icon": "fa fa-user",
|
||||||
"idx": 5,
|
"idx": 5,
|
||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-01-06 19:39:58.748978",
|
"modified": "2021-06-17 00:20:37.768449",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "CRM",
|
"module": "CRM",
|
||||||
"name": "Lead",
|
"name": "Lead",
|
||||||
|
|||||||
@ -21,14 +21,6 @@ class Lead(SellingController):
|
|||||||
self.get("__onload").is_customer = customer
|
self.get("__onload").is_customer = customer
|
||||||
load_address_and_contact(self)
|
load_address_and_contact(self)
|
||||||
|
|
||||||
def before_insert(self):
|
|
||||||
if self.address_title and self.address_type:
|
|
||||||
self.address_doc = self.create_address()
|
|
||||||
self.contact_doc = self.create_contact()
|
|
||||||
|
|
||||||
def after_insert(self):
|
|
||||||
self.update_links()
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.set_lead_name()
|
self.set_lead_name()
|
||||||
self.set_title()
|
self.set_title()
|
||||||
@ -120,85 +112,11 @@ class Lead(SellingController):
|
|||||||
self.lead_name = self.email_id.split("@")[0]
|
self.lead_name = self.email_id.split("@")[0]
|
||||||
|
|
||||||
def set_title(self):
|
def set_title(self):
|
||||||
if self.organization_lead:
|
if self.company_name:
|
||||||
self.title = self.company_name
|
self.title = self.company_name
|
||||||
else:
|
else:
|
||||||
self.title = self.lead_name
|
self.title = self.lead_name
|
||||||
|
|
||||||
def create_address(self):
|
|
||||||
address_fields = ["address_type", "address_title", "address_line1", "address_line2",
|
|
||||||
"city", "county", "state", "country", "pincode"]
|
|
||||||
info_fields = ["email_id", "phone", "fax"]
|
|
||||||
|
|
||||||
# do not create an address if no fields are available,
|
|
||||||
# skipping country since the system auto-sets it from system defaults
|
|
||||||
address = frappe.new_doc("Address")
|
|
||||||
|
|
||||||
address.update({addr_field: self.get(addr_field) for addr_field in address_fields})
|
|
||||||
address.update({info_field: self.get(info_field) for info_field in info_fields})
|
|
||||||
address.insert()
|
|
||||||
|
|
||||||
return address
|
|
||||||
|
|
||||||
def create_contact(self):
|
|
||||||
if not self.lead_name:
|
|
||||||
self.set_lead_name()
|
|
||||||
|
|
||||||
names = self.lead_name.strip().split(" ")
|
|
||||||
if len(names) > 1:
|
|
||||||
first_name, last_name = names[0], " ".join(names[1:])
|
|
||||||
else:
|
|
||||||
first_name, last_name = self.lead_name, None
|
|
||||||
|
|
||||||
contact = frappe.new_doc("Contact")
|
|
||||||
contact.update({
|
|
||||||
"first_name": first_name,
|
|
||||||
"last_name": last_name,
|
|
||||||
"salutation": self.salutation,
|
|
||||||
"gender": self.gender,
|
|
||||||
"designation": self.designation,
|
|
||||||
})
|
|
||||||
|
|
||||||
if self.email_id:
|
|
||||||
contact.append("email_ids", {
|
|
||||||
"email_id": self.email_id,
|
|
||||||
"is_primary": 1
|
|
||||||
})
|
|
||||||
|
|
||||||
if self.phone:
|
|
||||||
contact.append("phone_nos", {
|
|
||||||
"phone": self.phone,
|
|
||||||
"is_primary": 1
|
|
||||||
})
|
|
||||||
|
|
||||||
if self.mobile_no:
|
|
||||||
contact.append("phone_nos", {
|
|
||||||
"phone": self.mobile_no
|
|
||||||
})
|
|
||||||
|
|
||||||
contact.insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
return contact
|
|
||||||
|
|
||||||
def update_links(self):
|
|
||||||
# update address links
|
|
||||||
if hasattr(self, 'address_doc'):
|
|
||||||
self.address_doc.append("links", {
|
|
||||||
"link_doctype": "Lead",
|
|
||||||
"link_name": self.name,
|
|
||||||
"link_title": self.lead_name
|
|
||||||
})
|
|
||||||
self.address_doc.save()
|
|
||||||
|
|
||||||
# update contact links
|
|
||||||
if self.contact_doc:
|
|
||||||
self.contact_doc.append("links", {
|
|
||||||
"link_doctype": "Lead",
|
|
||||||
"link_name": self.name,
|
|
||||||
"link_title": self.lead_name
|
|
||||||
})
|
|
||||||
self.contact_doc.save()
|
|
||||||
|
|
||||||
@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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user