Skip to content

Commit

Permalink
Merge pull request #38 from shariquerik/sla
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik authored Dec 11, 2023
2 parents a86a1d6 + 5ab2ae8 commit bd51426
Show file tree
Hide file tree
Showing 26 changed files with 966 additions and 17 deletions.
65 changes: 63 additions & 2 deletions crm/fcrm/doctype/crm_deal/crm_deal.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@
"deal_owner",
"section_break_eepu",
"lead",
"column_break_bqvs"
"column_break_bqvs",
"sla_tab",
"sla",
"sla_creation",
"column_break_pfvq",
"sla_status",
"response_details_section",
"response_by",
"column_break_hpvj",
"first_response_time",
"first_responded_on"
],
"fields": [
{
Expand Down Expand Up @@ -134,11 +144,62 @@
"fieldname": "organization_tab",
"fieldtype": "Tab Break",
"label": "Organization"
},
{
"fieldname": "sla_tab",
"fieldtype": "Tab Break",
"label": "SLA",
"read_only": 1
},
{
"fieldname": "sla",
"fieldtype": "Link",
"label": "SLA",
"options": "CRM Service Level Agreement"
},
{
"fieldname": "response_by",
"fieldtype": "Datetime",
"label": "Response By"
},
{
"fieldname": "column_break_pfvq",
"fieldtype": "Column Break"
},
{
"fieldname": "sla_status",
"fieldtype": "Select",
"label": "SLA Status",
"options": "\nFirst Response Due\nFailed\nFulfilled"
},
{
"fieldname": "sla_creation",
"fieldtype": "Datetime",
"label": "SLA Creation"
},
{
"fieldname": "response_details_section",
"fieldtype": "Section Break",
"label": "Response Details"
},
{
"fieldname": "column_break_hpvj",
"fieldtype": "Column Break"
},
{
"fieldname": "first_response_time",
"fieldtype": "Duration",
"label": "First Response Time"
},
{
"fieldname": "first_responded_on",
"fieldtype": "Datetime",
"label": "First Responded On"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-29 11:31:46.968519",
"modified": "2023-12-11 12:37:51.198228",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal",
Expand Down
33 changes: 32 additions & 1 deletion crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@


class CRMDeal(Document):
def before_validate(self):
self.set_sla()

def validate(self):
self.set_primary_contact()
self.set_primary_email_mobile_no()

def before_save(self):
self.apply_sla()

def set_primary_contact(self, contact=None):
if not self.contacts:
return
Expand Down Expand Up @@ -45,6 +51,22 @@ def set_primary_email_mobile_no(self):
self.email = ""
self.mobile_no = ""

def set_sla(self):
"""
Find an SLA to apply to the deal.
"""
if sla := get_sla("CRM Deal"):
if not sla:
return
self.sla = sla.name

def apply_sla(self):
"""
Apply SLA if set.
"""
if sla := frappe.get_last_doc("CRM Service Level Agreement", {"name": self.sla}):
sla.apply(self)

@staticmethod
def sort_options():
return [
Expand Down Expand Up @@ -113,6 +135,9 @@ def default_list_data():
"email",
"mobile_no",
"deal_owner",
"sla_status",
"first_response_time",
"first_responded_on",
"modified",
]
return {'columns': columns, 'rows': rows}
Expand Down Expand Up @@ -145,4 +170,10 @@ def set_primary_contact(deal, contact):
deal = frappe.get_cached_doc("CRM Deal", deal)
deal.set_primary_contact(contact)
deal.save()
return True
return True

def get_sla(doctype):
sla = frappe.db.exists("CRM Service Level Agreement", {"apply_on": doctype, "enabled": 1})
if not sla:
return None
return frappe.get_cached_doc("CRM Service Level Agreement", sla)
65 changes: 63 additions & 2 deletions crm/fcrm/doctype/crm_lead/crm_lead.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@
"no_of_employees",
"annual_revenue",
"image",
"converted"
"converted",
"sla_tab",
"sla",
"sla_creation",
"column_break_ffnp",
"sla_status",
"response_details_section",
"response_by",
"column_break_pweh",
"first_response_time",
"first_responded_on"
],
"fields": [
{
Expand Down Expand Up @@ -196,12 +206,63 @@
"fieldname": "details",
"fieldtype": "Tab Break",
"label": "Details"
},
{
"fieldname": "sla_tab",
"fieldtype": "Tab Break",
"label": "SLA",
"read_only": 1
},
{
"fieldname": "sla",
"fieldtype": "Link",
"label": "SLA",
"options": "CRM Service Level Agreement"
},
{
"fieldname": "sla_creation",
"fieldtype": "Datetime",
"label": "SLA Creation"
},
{
"fieldname": "column_break_ffnp",
"fieldtype": "Column Break"
},
{
"fieldname": "sla_status",
"fieldtype": "Select",
"label": "SLA Status",
"options": "\nFirst Response Due\nFailed\nFulfilled"
},
{
"fieldname": "response_details_section",
"fieldtype": "Section Break",
"label": "Response Details"
},
{
"fieldname": "response_by",
"fieldtype": "Datetime",
"label": "Response By"
},
{
"fieldname": "column_break_pweh",
"fieldtype": "Column Break"
},
{
"fieldname": "first_response_time",
"fieldtype": "Duration",
"label": "First Response Time"
},
{
"fieldname": "first_responded_on",
"fieldtype": "Datetime",
"label": "First Responded On"
}
],
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-29 11:31:08.555096",
"modified": "2023-12-10 13:54:53.630114",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Lead",
Expand Down
33 changes: 32 additions & 1 deletion crm/fcrm/doctype/crm_lead/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@


class CRMLead(Document):
def before_validate(self):
self.set_sla()

def validate(self):
self.set_full_name()
self.set_lead_name()
self.set_title()
self.validate_email()

def before_save(self):
self.apply_sla()

def set_full_name(self):
if self.first_name:
self.lead_name = " ".join(
Expand Down Expand Up @@ -121,6 +127,22 @@ def create_deal(self, contact):
deal.insert(ignore_permissions=True)
return deal.name

def set_sla(self):
"""
Find an SLA to apply to the lead.
"""
if sla := get_sla("CRM Lead"):
if not sla:
return
self.sla = sla.name

def apply_sla(self):
"""
Apply SLA if set.
"""
if sla := frappe.get_last_doc("CRM Service Level Agreement", {"name": self.sla}):
sla.apply(self)

@staticmethod
def sort_options():
return [
Expand Down Expand Up @@ -193,6 +215,9 @@ def default_list_data():
"mobile_no",
"lead_owner",
"first_name",
"sla_status",
"first_response_time",
"first_responded_on",
"modified",
"image",
]
Expand All @@ -209,4 +234,10 @@ def convert_to_deal(lead):
contact = lead.create_contact(False)
deal = lead.create_deal(contact)
lead.save()
return deal
return deal

def get_sla(doctype):
sla = frappe.db.exists("CRM Service Level Agreement", {"apply_on": doctype, "enabled": 1})
if not sla:
return None
return frappe.get_cached_doc("CRM Service Level Agreement", sla)
Empty file.
59 changes: 59 additions & 0 deletions crm/fcrm/doctype/crm_service_day/crm_service_day.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-12-04 16:07:20.400084",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"workday",
"section_break_uegc",
"start_time",
"column_break_maie",
"end_time"
],
"fields": [
{
"fieldname": "workday",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Workday",
"options": "Monday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\nSunday",
"reqd": 1
},
{
"fieldname": "section_break_uegc",
"fieldtype": "Section Break"
},
{
"fieldname": "start_time",
"fieldtype": "Time",
"in_list_view": 1,
"label": "Start Time",
"reqd": 1
},
{
"fieldname": "column_break_maie",
"fieldtype": "Column Break"
},
{
"fieldname": "end_time",
"fieldtype": "Time",
"in_list_view": 1,
"label": "End Time",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-12-04 16:09:22.928308",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Service Day",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_service_day/crm_service_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class CRMServiceDay(Document):
pass
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

// frappe.ui.form.on("CRM Service Level Agreement", {
// refresh(frm) {

// },
// });

frappe.ui.form.on("CRM Service Level Priority", {
priorities_add: function (frm, cdt, cdn) {
if (frm.doc.apply_on == "CRM Deal") {
frappe.model.set_value(
cdt,
cdn,
"reference_doctype",
"CRM Deal Status"
);
}
},
});
Loading

0 comments on commit bd51426

Please sign in to comment.