fix: change agreement status only if ongoing
This commit is contained in:
parent
c5999154e6
commit
cf37e401f8
@ -264,7 +264,8 @@ scheduler_events = {
|
||||
"erpnext.projects.doctype.project.project.update_project_sales_billing",
|
||||
"erpnext.projects.doctype.project.project.send_project_status_email_to_users",
|
||||
"erpnext.quality_management.doctype.quality_review.quality_review.review",
|
||||
"erpnext.support.doctype.service_level_agreement.service_level_agreement.check_agreement_status"
|
||||
"erpnext.support.doctype.service_level_agreement.service_level_agreement.check_agreement_status",
|
||||
"erpnext.support.doctype.issue.issue.set_service_level_agreement_status"
|
||||
],
|
||||
"daily_long": [
|
||||
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_latest_price_in_all_boms"
|
||||
|
@ -77,9 +77,9 @@ class Issue(Document):
|
||||
|
||||
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):
|
||||
if self.service_level_agreement and self.agreement_status == "Ongoing":
|
||||
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"
|
||||
@ -220,6 +220,17 @@ def get_expected_time_for(parameter, service_level, start_date_time):
|
||||
|
||||
return current_date_time
|
||||
|
||||
def set_service_level_agreement_status():
|
||||
issues = frappe.get_list("Issue", filters={"status": "Open", "agreement_status": "Ongoing"})
|
||||
for issue in issues:
|
||||
doc = frappe.get_doc("Issue", issue.name)
|
||||
if self.service_level_agreement and self.agreement_status == "Ongoing":
|
||||
if (round(time_diff_in_hours(self.response_by, now_datetime()), 2) < 0 or
|
||||
round(time_diff_in_hours(self.resolution_by, now_datetime()), 2) < 0):
|
||||
frappe.db.set_value("Issue", doc.name, "agreement_status", "Failed")
|
||||
else:
|
||||
frappe.db.set_value("Issue", doc.name, "agreement_status", "Fulfilled")
|
||||
|
||||
def get_list_context(context=None):
|
||||
return {
|
||||
"title": _("Issues"),
|
||||
|
@ -48,18 +48,6 @@ class TestIssue(unittest.TestCase):
|
||||
|
||||
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=None, customer=None):
|
||||
|
||||
issue = frappe.get_doc({
|
||||
|
@ -30,11 +30,9 @@ def check_agreement_status():
|
||||
service_level_agreements = frappe.get_list("Service Level Agreement", filters=[
|
||||
{"agreement_status": "Active"},
|
||||
{"default_service_level_agreement": 0}
|
||||
])
|
||||
], fields=["name", "end_date"])
|
||||
|
||||
for service_level_agreement in service_level_agreements:
|
||||
service_level_agreement = frappe.get_doc("Service Level Agreement", service_level_agreement)
|
||||
|
||||
if service_level_agreement.end_date < frappe.utils.getdate():
|
||||
frappe.db.set_value("Service Level Agreement", service_level_agreement.name,
|
||||
"agreement_status", "Expired")
|
||||
|
Loading…
x
Reference in New Issue
Block a user