feat: update sla using custom script

This commit is contained in:
Himanshu Warekar 2019-06-20 11:32:49 +05:30
parent d82175da36
commit a03aa0014e
2 changed files with 22 additions and 9 deletions

View File

@ -76,8 +76,6 @@ class Issue(Document):
self.resolution_date = None
def update_agreement_status(self):
current_time = frappe.flags.current_time or now_datetime()
if self.service_level_agreement and self.agreement_fulfilled == "Ongoing":
if frappe.db.get_value("Issue", self.name, "response_by_variance") < 0 or \
frappe.db.get_value("Issue", self.name, "resolution_by_variance") < 0:
@ -86,6 +84,19 @@ class Issue(Document):
else:
self.agreement_fulfilled = "Fulfilled"
def update_agreement_fulfilled_on_custom_status(self):
"""
Update Agreement Fulfilled status using Custom Scripts for Custom Issue Status
"""
if not self.first_responded_on: # first_responded_on set when first reply is sent to customer
self.response_by_variance = round(time_diff_in_hours(self.response_by, now_datetime()), 2)
if not self.resolution_date: # resolution_date set when issue has been closed
self.resolution_by_variance = round(time_diff_in_hours(self.resolution_by, now_datetime()), 2)
self.agreement_fulfilled = "Fulfilled" if self.response_by_variance > 0 and self.resolution_by_variance > 0 else "Failed"
self.save(ignore_permissions=True)
def create_communication(self):
communication = frappe.new_doc("Communication")
communication.update({

View File

@ -71,14 +71,16 @@ def get_service_level_agreement_priorities(name):
return [priority.priority for priority in frappe.get_list("Service Level Priority", filters={"parent": name}, fields=["priority"])]
@frappe.whitelist()
def get_valid_service_level_agreements(customer):
or_filters = [
["Service Level Agreement", "entity", "in", [customer, get_customer_group(customer), get_customer_territory(customer), "IS NULL"]],
["Service Level Agreement", "default_service_level_agreement", "=", 1]
]
def get_valid_service_level_agreements(customer=None):
if not customer:
or_filters = ["Service Level Agreement", "default_service_level_agreement", "=", 1]
or_filters = [
["Service Level Agreement", "default_service_level_agreement", "=", 1]
]
else:
or_filters = [
["Service Level Agreement", "entity", "in", [customer, get_customer_group(customer), get_customer_territory(customer), "IS NULL"]],
["Service Level Agreement", "default_service_level_agreement", "=", 1]
]
return [d.name for d in frappe.get_list("Service Level Agreement", or_filters=or_filters)]