fix: set total hold time only if hold configurations are enabled

This commit is contained in:
Rucha Mahabal 2020-06-19 17:27:25 +05:30
parent 28c1e8ef77
commit 5dd4bcb229

View File

@ -85,6 +85,7 @@ class Issue(Document):
hold_statuses = [entry.status for entry in pause_sla_on]
update_values = {}
if hold_statuses:
if self.status in hold_statuses and status not in hold_statuses:
update_values['on_hold_since'] = frappe.flags.current_time or now_datetime()
if not self.first_responded_on:
@ -97,27 +98,30 @@ class Issue(Document):
if self.status not in hold_statuses and status in hold_statuses:
hold_time = self.total_hold_time if self.total_hold_time else 0
now_time = frappe.flags.current_time or now_datetime()
update_values['total_hold_time'] = hold_time + time_diff_in_seconds(now_time, self.on_hold_since)
last_hold_time = 0
if self.on_hold_since:
# last_hold_time will be added to the sla variables
last_hold_time = time_diff_in_seconds(now_time, self.on_hold_since)
update_values['total_hold_time'] = hold_time + last_hold_time
# re-calculate SLA variables after issue changes from any hold status to any non-hold status
# add hold time to SLA variables
start_date_time = get_datetime(self.service_level_agreement_creation)
priority = get_priority(self)
now_time = frappe.flags.current_time or now_datetime()
hold_time = time_diff_in_seconds(now_time, self.on_hold_since)
if not self.first_responded_on:
response_by = get_expected_time_for(parameter="response", service_level=priority, start_date_time=start_date_time)
response_by = add_to_date(response_by, seconds=round(hold_time))
response_by = add_to_date(response_by, seconds=round(last_hold_time))
response_by_variance = round(time_diff_in_hours(response_by, now_time))
update_values['response_by'] = response_by
update_values['response_by_variance'] = response_by_variance + (hold_time // 3600)
update_values['response_by_variance'] = response_by_variance + (last_hold_time // 3600)
resolution_by = get_expected_time_for(parameter="resolution", service_level=priority, start_date_time=start_date_time)
resolution_by = add_to_date(resolution_by, seconds=round(hold_time))
resolution_by = add_to_date(resolution_by, seconds=round(last_hold_time))
resolution_by_variance = round(time_diff_in_hours(resolution_by, now_time))
update_values['resolution_by'] = resolution_by
update_values['resolution_by_variance'] = resolution_by_variance + (hold_time // 3600)
update_values['resolution_by_variance'] = resolution_by_variance + (last_hold_time // 3600)
update_values['on_hold_since'] = None
self.db_set(update_values)