From 78b935373523750d72b10b1d88a61c3450277b0d Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 11 Dec 2023 12:57:00 +0530 Subject: [PATCH] fix: show sla details on deal page --- crm/fcrm/doctype/crm_deal/crm_deal.py | 30 +++++++++- frontend/src/pages/Deal.vue | 84 ++++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 2 deletions(-) diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index 78032c55..f9f3ee7c 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -7,10 +7,16 @@ from frappe.model.document import Document 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 @@ -45,6 +51,22 @@ class CRMDeal(Document): 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 [ @@ -145,4 +167,10 @@ def set_primary_contact(deal, contact): deal = frappe.get_cached_doc("CRM Deal", deal) deal.set_primary_contact(contact) deal.save() - return True \ No newline at end of file + 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) diff --git a/frontend/src/pages/Deal.vue b/frontend/src/pages/Deal.vue index 007c321b..2b122b11 100644 --- a/frontend/src/pages/Deal.vue +++ b/frontend/src/pages/Deal.vue @@ -94,6 +94,72 @@ +
+
+
Response By
+ + {{ timeAgo(deal.data.response_by) }} + +
+
+
Fulfilled In
+ + {{ formatTime(deal.data.first_response_time) }} + +
+
+
Fulfilled In
+ + {{ formatTime(deal.data.first_response_time) }} + +
+
+
Status
+
+ +
+
+
{ + if ( + data.response_by && + data.sla_status == 'First Response Due' && + new Date(data.response_by) < new Date() + ) { + updateField('sla_status', 'Failed') + } + }, }) const reload = ref(false)