refactor: lead

This commit is contained in:
Anupam 2021-06-17 00:28:03 +05:30
parent 80077d215f
commit dc448c2f51
3 changed files with 107 additions and 168 deletions

View File

@ -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 () {
if (this.frm.doc.organization_lead && !this.frm.doc.lead_name) {
this.frm.set_value("lead_name", this.frm.doc.company_name);

View File

@ -9,30 +9,32 @@
"email_append_to": 1,
"engine": "InnoDB",
"field_order": [
"organization_lead",
"lead_details",
"naming_series",
"lead_name",
"company_name",
"email_id",
"col_break123",
"lead_owner",
"status",
"salutation",
"first_name",
"middle_name",
"last_name",
"lead_name",
"email_id",
"mobile_no",
"phone",
"col_break123",
"status",
"company_name",
"designation",
"gender",
"source",
"customer",
"campaign_name",
"image",
"section_break_12",
"contact_by",
"column_break_14",
"contact_date",
"ends_on",
"notes_section",
"notes",
"address_info",
"additional_information_section",
"no_of_employees",
"industry",
"market_segment",
"type",
"request_type",
"column_break_22",
"whatsapp_no",
"fax",
"website",
"address_section",
"address_html",
"address_type",
"address_title",
@ -45,35 +47,33 @@
"state",
"country",
"pincode",
"contact_section",
"phone",
"mobile_no",
"fax",
"website",
"more_info",
"type",
"market_segment",
"industry",
"request_type",
"column_break3",
"section_break_12",
"lead_owner",
"ends_on",
"column_break_14",
"contact_by",
"contact_date",
"lead_source_details_section",
"company",
"territory",
"language",
"column_break_50",
"source",
"campaign_name",
"unsubscribed",
"blog_subscriber",
"notes_section",
"notes",
"other_information_section",
"customer",
"image",
"title"
],
"fields": [
{
"default": "0",
"fieldname": "organization_lead",
"fieldtype": "Check",
"label": "Lead is an Organization",
"set_only_once": 1
},
{
"fieldname": "lead_details",
"fieldtype": "Section Break",
"label": "Lead Details",
"options": "fa fa-user"
},
{
@ -90,7 +90,8 @@
"fieldname": "lead_name",
"fieldtype": "Data",
"in_global_search": 1,
"label": "Person Name",
"label": "Full Name",
"mandatory_depends_on": "eval: !(doc.company_name)",
"oldfieldname": "lead_name",
"oldfieldtype": "Data",
"search_index": 1
@ -99,7 +100,9 @@
"fieldname": "company_name",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Organization Name",
"mandatory_depends_on": "eval: !(doc.lead_name)",
"oldfieldname": "company_name",
"oldfieldtype": "Data"
},
@ -121,7 +124,6 @@
"default": "__user",
"fieldname": "lead_owner",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Lead Owner",
"oldfieldname": "lead_owner",
"oldfieldtype": "Link",
@ -241,46 +243,39 @@
"read_only": 1
},
{
"depends_on": "eval: doc.__islocal",
"description": "Home, Work, etc.",
"fieldname": "address_title",
"fieldtype": "Data",
"label": "Address Title"
},
{
"depends_on": "eval: doc.__islocal",
"fieldname": "address_line1",
"fieldtype": "Data",
"label": "Address Line 1",
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
},
{
"depends_on": "eval: doc.__islocal",
"fieldname": "address_line2",
"fieldtype": "Data",
"label": "Address Line 2"
},
{
"depends_on": "eval: doc.__islocal",
"fieldname": "city",
"fieldtype": "Data",
"label": "City/Town",
"mandatory_depends_on": "eval: doc.address_title && doc.address_type"
},
{
"depends_on": "eval: doc.__islocal",
"fieldname": "county",
"fieldtype": "Data",
"label": "County"
},
{
"depends_on": "eval: doc.__islocal",
"fieldname": "state",
"fieldtype": "Data",
"label": "State"
},
{
"depends_on": "eval: doc.__islocal",
"fieldname": "country",
"fieldtype": "Link",
"label": "Country",
@ -288,7 +283,7 @@
"options": "Country"
},
{
"depends_on": "eval: doc.__islocal",
"collapsible_depends_on": "eval: doc.__islocal",
"fieldname": "pincode",
"fieldtype": "Data",
"label": "Postal Code"
@ -329,14 +324,6 @@
"oldfieldname": "fax",
"oldfieldtype": "Data"
},
{
"collapsible": 1,
"fieldname": "more_info",
"fieldtype": "Section Break",
"label": "More Information",
"oldfieldtype": "Section Break",
"options": "fa fa-file-text"
},
{
"fieldname": "type",
"fieldtype": "Select",
@ -369,12 +356,6 @@
"oldfieldtype": "Select",
"options": "\nProduct Enquiry\nRequest for Information\nSuggestions\nOther"
},
{
"fieldname": "column_break3",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"width": "50%"
},
{
"fieldname": "company",
"fieldtype": "Link",
@ -389,11 +370,14 @@
"fieldtype": "Data",
"label": "Website",
"oldfieldname": "website",
"oldfieldtype": "Data"
"oldfieldtype": "Data",
"options": "URL"
},
{
"fieldname": "territory",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Territory",
"oldfieldname": "territory",
"oldfieldtype": "Link",
@ -422,28 +406,13 @@
{
"fieldname": "designation",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "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",
"depends_on": "eval: doc.__islocal",
"fieldname": "address_type",
"fieldtype": "Select",
"label": "Address Type",
@ -454,13 +423,70 @@
"fieldtype": "Link",
"label": "Print 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",
"idx": 5,
"image_field": "image",
"links": [],
"modified": "2021-01-06 19:39:58.748978",
"modified": "2021-06-17 00:20:37.768449",
"modified_by": "Administrator",
"module": "CRM",
"name": "Lead",

View File

@ -21,14 +21,6 @@ class Lead(SellingController):
self.get("__onload").is_customer = customer
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):
self.set_lead_name()
self.set_title()
@ -120,85 +112,11 @@ class Lead(SellingController):
self.lead_name = self.email_id.split("@")[0]
def set_title(self):
if self.organization_lead:
if self.company_name:
self.title = self.company_name
else:
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()
def make_customer(source_name, target_doc=None):
return _make_customer(source_name, target_doc)