fix: handle custom statuses for the pause SLA configuration (#22349)
* fix: handle hold time for custom statuses * fix: set total hold time only if hold configurations are enabled Co-authored-by: Himanshu <himanshuwarekar@yahoo.com>
This commit is contained in:
parent
53346217d2
commit
7b3700b3ec
@ -79,47 +79,52 @@ class Issue(Document):
|
|||||||
|
|
||||||
def handle_hold_time(self, status):
|
def handle_hold_time(self, status):
|
||||||
if self.service_level_agreement:
|
if self.service_level_agreement:
|
||||||
# set response and resolution variance as None as the issue is on Hold for status as Replied
|
# set response and resolution variance as None as the issue is on Hold
|
||||||
pause_sla_on = frappe.db.get_all("Pause SLA On Status", fields=["status"],
|
pause_sla_on = frappe.db.get_all("Pause SLA On Status", fields=["status"],
|
||||||
filters={"parent": self.service_level_agreement})
|
filters={"parent": self.service_level_agreement})
|
||||||
hold_statuses = [entry.status for entry in pause_sla_on]
|
hold_statuses = [entry.status for entry in pause_sla_on]
|
||||||
update_values = {}
|
update_values = {}
|
||||||
|
|
||||||
if self.status in hold_statuses and status not in hold_statuses:
|
if hold_statuses:
|
||||||
update_values['on_hold_since'] = frappe.flags.current_time or now_datetime()
|
if self.status in hold_statuses and status not in hold_statuses:
|
||||||
if not self.first_responded_on:
|
update_values['on_hold_since'] = frappe.flags.current_time or now_datetime()
|
||||||
update_values['response_by'] = None
|
if not self.first_responded_on:
|
||||||
update_values['response_by_variance'] = 0
|
update_values['response_by'] = None
|
||||||
update_values['resolution_by'] = None
|
update_values['response_by_variance'] = 0
|
||||||
update_values['resolution_by_variance'] = 0
|
update_values['resolution_by'] = None
|
||||||
|
update_values['resolution_by_variance'] = 0
|
||||||
|
|
||||||
# calculate hold time when status is changed from Replied to any other status
|
# calculate hold time when status is changed from any hold status to any non-hold status
|
||||||
if self.status not in hold_statuses and status in hold_statuses:
|
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
|
hold_time = self.total_hold_time if self.total_hold_time else 0
|
||||||
now_time = frappe.flags.current_time or now_datetime()
|
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 Replied to Open
|
# re-calculate SLA variables after issue changes from any hold status to any non-hold status
|
||||||
# add hold time to SLA variables
|
# add hold time to SLA variables
|
||||||
if self.status == "Open" and status in hold_statuses:
|
start_date_time = get_datetime(self.service_level_agreement_creation)
|
||||||
start_date_time = get_datetime(self.service_level_agreement_creation)
|
priority = get_priority(self)
|
||||||
priority = get_priority(self)
|
now_time = frappe.flags.current_time or now_datetime()
|
||||||
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:
|
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 = get_expected_time_for(parameter="response", service_level=priority, start_date_time=start_date_time)
|
||||||
update_values['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(self.response_by, now_time))
|
response_by_variance = round(time_diff_in_hours(response_by, now_time))
|
||||||
update_values['response_by_variance'] = response_by_variance + (hold_time // 3600)
|
update_values['response_by'] = response_by
|
||||||
|
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 = get_expected_time_for(parameter="resolution", service_level=priority, start_date_time=start_date_time)
|
||||||
update_values['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(self.resolution_by, now_time))
|
resolution_by_variance = round(time_diff_in_hours(resolution_by, now_time))
|
||||||
update_values['resolution_by_variance'] = resolution_by_variance + (hold_time // 3600)
|
update_values['resolution_by'] = resolution_by
|
||||||
update_values['on_hold_since'] = None
|
update_values['resolution_by_variance'] = resolution_by_variance + (last_hold_time // 3600)
|
||||||
|
update_values['on_hold_since'] = None
|
||||||
|
|
||||||
self.db_set(update_values)
|
self.db_set(update_values)
|
||||||
|
|
||||||
def update_agreement_status(self):
|
def update_agreement_status(self):
|
||||||
if self.service_level_agreement and self.agreement_fulfilled == "Ongoing":
|
if self.service_level_agreement and self.agreement_fulfilled == "Ongoing":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user