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 @@ +