fix(sla): update agreement status on save'

This commit is contained in:
Rushabh Mehta 2019-03-28 18:49:23 +05:30
parent a8c9b81d93
commit cf33f4fd53
3 changed files with 29 additions and 14 deletions

View File

@ -241,8 +241,7 @@ scheduler_events = {
"erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_mws_settings.schedule_get_order_details",
"erpnext.accounts.doctype.gl_entry.gl_entry.rename_gle_sle_docs",
"erpnext.projects.doctype.project.project.hourly_reminder",
"erpnext.projects.doctype.project.project.collect_project_status",
"erpnext.support.doctype.issue.issue.update_support_timer",
"erpnext.projects.doctype.project.project.collect_project_status"
],
"daily": [
"erpnext.stock.reorder_item.reorder_item",

View File

@ -65,10 +65,20 @@ class Issue(Document):
self.first_responded_on = now()
if self.status=="Closed" and status !="Closed":
self.resolution_date = now()
self.update_agreement_status()
if self.status=="Open" and status !="Open":
# if no date, it should be set as None and not a blank string "", as per mysql strict config
self.resolution_date = None
def update_agreement_status(self):
current_time = frappe.flags.current_time or now_datetime()
if self.service_level_agreement:
if (round(time_diff_in_hours(self.response_by, current_time), 2) < 0
or round(time_diff_in_hours(self.resolution_by, current_time), 2) < 0):
self.agreement_status = "Failed"
else:
self.agreement_status = "Fulfilled"
def create_communication(self):
communication = frappe.new_doc("Communication")
communication.update({
@ -265,18 +275,6 @@ def update_issue(contact, method):
"""Called when Contact is deleted"""
frappe.db.sql("""UPDATE `tabIssue` set contact='' where contact=%s""", contact.name)
def update_support_timer():
issues = frappe.get_list("Issue", filters={"status": "Open"}, order_by="creation DESC")
for issue in issues:
issue = frappe.get_doc("Issue", issue.name)
if round(time_diff_in_hours(issue.response_by, now_datetime()), 2) < 0 or round(time_diff_in_hours(issue.resolution_by, now_datetime()), 2) < 0:
issue.agreement_status = "Failed"
else:
issue.agreement_status = "Fulfilled"
issue.save()
def get_holidays(holiday_list_name):
holiday_list = frappe.get_cached_doc("Holiday List", holiday_list_name)
holidays = [holiday.holiday_date for holiday in holiday_list.holidays]

View File

@ -35,6 +35,24 @@ class TestIssue(unittest.TestCase):
self.assertEquals(issue.response_by, datetime.datetime(2019, 3, 4, 18, 0))
self.assertEquals(issue.resolution_by, datetime.datetime(2019, 3, 6, 12, 0))
frappe.flags.current_time = datetime.datetime(2019, 3, 3, 12, 0)
issue.status = 'Closed'
issue.save()
self.assertEqual(issue.agreement_status, 'Fulfilled')
issue.status = 'Open'
issue.save()
frappe.flags.current_time = datetime.datetime(2019, 3, 5, 12, 0)
issue.status = 'Closed'
issue.save()
self.assertEqual(issue.agreement_status, 'Failed')
def make_issue(creation, customer=None):