Skip to content

Commit

Permalink
Merge pull request #12 from rtCamp/fix/lead-quick-entry
Browse files Browse the repository at this point in the history
fix: add log to lead and use customer_name
  • Loading branch information
Aryan20 authored Nov 12, 2024
2 parents 06994a5 + 4991072 commit d049067
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 59 deletions.
108 changes: 108 additions & 0 deletions crm/fixtures/custom_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,114 @@
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Lead",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "log",
"fieldtype": "Tab Break",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "first_responded_on",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Log",
"length": 0,
"mandatory_depends_on": null,
"modified": "2024-11-13 00:02:24.878678",
"module": "FCRM",
"name": "Lead-log",
"no_copy": 0,
"non_negative": 0,
"options": null,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Lead",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "status_change_log",
"fieldtype": "Table",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "log",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Status Change Log",
"length": 0,
"mandatory_depends_on": null,
"modified": "2024-11-13 00:02:24.751266",
"module": "FCRM",
"name": "Lead-status_change_log",
"no_copy": 0,
"non_negative": 0,
"options": "CRM Status Change Log",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
Expand Down
2 changes: 1 addition & 1 deletion crm/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def add_default_fields_layout(force=False):
quick_entry_layouts = {
"Lead-Quick Entry": {
"doctype": "Lead",
"layout": '[{"label":"Person","fields":["salutation","first_name","last_name","email_id","mobile_no", "gender"],"hideLabel":true},{"label":"Customer","fields":["customer","website","no_of_employees","territory","annual_revenue","industry"],"hideLabel":true,"hideBorder":false},{"label":"Other","columns":2,"fields":["status","lead_owner"],"hideLabel":true,"hideBorder":false}]'
"layout": '[{"label":"Person","fields":["salutation","first_name","last_name","email_id","mobile_no", "gender"],"hideLabel":true},{"label":"Customer","fields":["company_name","website","no_of_employees","territory","annual_revenue","industry"],"hideLabel":true,"hideBorder":false},{"label":"Other","columns":2,"fields":["status","lead_owner"],"hideLabel":true,"hideBorder":false}]'
},
"Opportunity-Quick Entry": {
"doctype": "Opportunity",
Expand Down
77 changes: 19 additions & 58 deletions crm/overrides/lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,14 @@
from frappe import _
from frappe.desk.form.assign_to import add as assign

from frappe.utils import has_gravatar, validate_email_address
from erpnext.crm.doctype.lead.lead import Lead
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
from crm.fcrm.doctype.crm_status_change_log.crm_status_change_log import add_status_change_log


class Lead(Lead):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from erpnext.crm.doctype.crm_note.crm_note import CRMNote
from frappe.types import DF

annual_revenue: DF.Currency
blog_subscriber: DF.Check
campaign_name: DF.Link | None
city: DF.Data | None
company: DF.Link | None
company_name: DF.Data | None
country: DF.Link | None
customer: DF.Link | None
disabled: DF.Check
email_id: DF.Data | None
fax: DF.Data | None
first_name: DF.Data | None
gender: DF.Link | None
image: DF.AttachImage | None
industry: DF.Link | None
job_title: DF.Data | None
language: DF.Link | None
last_name: DF.Data | None
lead_name: DF.Data | None
lead_owner: DF.Link | None
market_segment: DF.Link | None
middle_name: DF.Data | None
mobile_no: DF.Data | None
naming_series: DF.Literal["CRM-LEAD-.YYYY.-"]
no_of_employees: DF.Literal["1-10", "11-50", "51-200", "201-500", "501-1000", "1000+"]
notes: DF.Table[CRMNote]
phone: DF.Data | None
phone_ext: DF.Data | None
qualification_status: DF.Literal["Unqualified", "In Process", "Qualified"]
qualified_by: DF.Link | None
qualified_on: DF.Date | None
request_type: DF.Literal["", "Product Enquiry", "Request for Information", "Suggestions", "Other"]
salutation: DF.Link | None
source: DF.Link | None
state: DF.Data | None
status: DF.Literal["Lead", "Open", "Replied", "Opportunity", "Quotation", "Lost Quotation", "Interested", "Converted", "Do Not Contact"]
territory: DF.Link | None
title: DF.Data | None
type: DF.Literal["", "Client", "Channel Partner", "Consultant"]
unsubscribed: DF.Check
website: DF.Data | None
whatsapp_no: DF.Data | None
# end: auto-generated types

def before_validate(self):
self.set_sla()
super()
Expand All @@ -73,8 +23,8 @@ def validate(self):
if not self.is_new() and self.has_value_changed("lead_owner") and self.lead_owner:
self.share_with_agent(self.lead_owner)
self.assign_agent(self.lead_owner)
# if self.has_value_changed("status"):
# add_status_change_log(self)
if self.has_value_changed("status"):
add_status_change_log(self)

def after_insert(self):
if self.lead_owner:
Expand All @@ -85,6 +35,17 @@ def before_save(self):
self.apply_sla()
super()

def validate_email(self):
if self.email:
if not self.flags.ignore_email_validation:
validate_email_address(self.email, throw=True)

if self.email == self.lead_owner:
frappe.throw(_("Lead Owner cannot be same as the Lead Email Address"))

if self.is_new() or not self.image:
self.image = has_gravatar(self.email)

def assign_agent(self, agent):
if not agent:
return
Expand Down Expand Up @@ -155,17 +116,17 @@ def create_contact(self, throw=True):
return contact.name

def create_customer(self):
if not self.customer:
if not self.company_name:
return

existing_customer = frappe.db.exists("Customer", {"customer_name": self.customer})
existing_customer = frappe.db.exists("Customer", {"customer_name": self.company_name})
if existing_customer:
return existing_customer

customer = frappe.new_doc("Customer")
customer.update(
{
"customer_name": self.customer,
"customer_name": self.company_name,
"website": self.website,
"territory": self.territory,
"industry": self.industry,
Expand Down Expand Up @@ -291,7 +252,7 @@ def default_list_data():
{
'label': 'Customer',
'type': 'Link',
'key': 'customer',
'key': 'company_name',
'options': 'Customer',
'width': '10rem',
},
Expand Down

0 comments on commit d049067

Please sign in to comment.