fix(sla): update agreement status on save'
This commit is contained in:
parent
a8c9b81d93
commit
cf33f4fd53
@ -241,8 +241,7 @@ scheduler_events = {
|
|||||||
"erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_mws_settings.schedule_get_order_details",
|
"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.accounts.doctype.gl_entry.gl_entry.rename_gle_sle_docs",
|
||||||
"erpnext.projects.doctype.project.project.hourly_reminder",
|
"erpnext.projects.doctype.project.project.hourly_reminder",
|
||||||
"erpnext.projects.doctype.project.project.collect_project_status",
|
"erpnext.projects.doctype.project.project.collect_project_status"
|
||||||
"erpnext.support.doctype.issue.issue.update_support_timer",
|
|
||||||
],
|
],
|
||||||
"daily": [
|
"daily": [
|
||||||
"erpnext.stock.reorder_item.reorder_item",
|
"erpnext.stock.reorder_item.reorder_item",
|
||||||
|
@ -65,10 +65,20 @@ class Issue(Document):
|
|||||||
self.first_responded_on = now()
|
self.first_responded_on = now()
|
||||||
if self.status=="Closed" and status !="Closed":
|
if self.status=="Closed" and status !="Closed":
|
||||||
self.resolution_date = now()
|
self.resolution_date = now()
|
||||||
|
self.update_agreement_status()
|
||||||
if self.status=="Open" and status !="Open":
|
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
|
# if no date, it should be set as None and not a blank string "", as per mysql strict config
|
||||||
self.resolution_date = None
|
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):
|
def create_communication(self):
|
||||||
communication = frappe.new_doc("Communication")
|
communication = frappe.new_doc("Communication")
|
||||||
communication.update({
|
communication.update({
|
||||||
@ -265,18 +275,6 @@ def update_issue(contact, method):
|
|||||||
"""Called when Contact is deleted"""
|
"""Called when Contact is deleted"""
|
||||||
frappe.db.sql("""UPDATE `tabIssue` set contact='' where contact=%s""", contact.name)
|
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):
|
def get_holidays(holiday_list_name):
|
||||||
holiday_list = frappe.get_cached_doc("Holiday List", holiday_list_name)
|
holiday_list = frappe.get_cached_doc("Holiday List", holiday_list_name)
|
||||||
holidays = [holiday.holiday_date for holiday in holiday_list.holidays]
|
holidays = [holiday.holiday_date for holiday in holiday_list.holidays]
|
||||||
|
@ -35,6 +35,24 @@ class TestIssue(unittest.TestCase):
|
|||||||
self.assertEquals(issue.response_by, datetime.datetime(2019, 3, 4, 18, 0))
|
self.assertEquals(issue.response_by, datetime.datetime(2019, 3, 4, 18, 0))
|
||||||
self.assertEquals(issue.resolution_by, datetime.datetime(2019, 3, 6, 12, 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):
|
def make_issue(creation, customer=None):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user