Skip to content

Commit

Permalink
chore: move first_responded_on from sla to ticket (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad authored Sep 18, 2023
1 parent b5e9162 commit ba1a671
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Status",
"options": "Open\nReplied\nResolved\nClosed",
"reqd": 1
}
],
"istable": 1,
"links": [],
"migration_hash": "ce4e06e89021c8f57de5128bf63dd079",
"modified": "2021-10-21 14:27:08.994829",
"modified": "2023-09-18 12:23:59.039194",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Pause Service Level Agreement On Status",
Expand All @@ -28,5 +28,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
get_datetime,
get_weekdays,
getdate,
get_datetime,
now_datetime,
time_diff_in_seconds,
to_timedelta,
Expand Down Expand Up @@ -120,8 +119,8 @@ def on_trash(self):

def apply(self, doc: Document):
self.handle_new(doc)
self.handle_targets(doc)
self.handle_status(doc)
self.handle_targets(doc)
self.handle_agreement_status(doc)

def handle_new(self, doc: Document):
Expand All @@ -134,19 +133,15 @@ def handle_new(self, doc: Document):
def handle_status(self, doc: Document):
if doc.is_new() or not doc.has_value_changed("status"):
return
self.set_first_responded_at(doc)
self.set_first_response_time(doc)
self.set_resolution_date(doc)
self.set_hold_time(doc)

def set_first_responded_at(self, doc: Document):
next_state = doc.get("status")
pause_on = [row.status for row in self.pause_sla_on]
is_paused = next_state in pause_on
if not is_paused:
return
doc.first_responded_on = doc.first_responded_on or now_datetime()
def set_first_response_time(self, doc: Document):
start_at = doc.service_level_agreement_creation
end_at = doc.first_responded_on
if not start_at or not end_at:
return
doc.first_response_time = self.calc_elapsed_time(start_at, end_at)

def set_resolution_date(self, doc: Document):
Expand Down Expand Up @@ -187,8 +182,21 @@ def set_hold_time(self, doc: Document):
doc.total_hold_time = (doc.total_hold_time or 0) + curr_val

def handle_targets(self, doc: Document):
doc.response_by = self.calc_time(doc, "response_time")
doc.resolution_by = self.calc_time(doc, "resolution_time")
self.set_response_by(doc)
self.set_resolution_by(doc)

def set_response_by(self, doc: Document):
start = doc.service_level_agreement_creation
doc.response_by = self.calc_time(start, doc.priority, "response_time")

def set_resolution_by(self, doc: Document):
total_hold_time = doc.total_hold_time or 0
start = add_to_date(
doc.service_level_agreement_creation,
seconds=total_hold_time,
as_datetime=True,
)
doc.resolution_by = self.calc_time(start, doc.priority, "resolution_time")

def reset_resolution_metrics(self, doc: Document):
pause_on = [row.status for row in self.pause_sla_on]
Expand Down Expand Up @@ -232,10 +240,13 @@ def is_resolution_failed(self, doc: Document):
return get_datetime(doc.resolution_by) < get_datetime(doc.resolution_date)

def calc_time(
self, doc: Document, target: Literal["response_time", "resolution_time"]
self,
start_at: str,
priority: str,
target: Literal["response_time", "resolution_time"],
):
res = get_datetime(doc.service_level_agreement_creation or doc.creation)
priority = self.get_priorities()[doc.priority]
res = get_datetime(start_at)
priority = self.get_priorities()[priority]
time_needed = priority.get(target, 0)
holidays = self.get_holidays()
weekdays = get_weekdays()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Status",
"options": "Open\nReplied\nResolved\nClosed",
"reqd": 1
}
],
"istable": 1,
"links": [],
"migration_hash": "bca91b0e57956157b4326c47cbc90187",
"modified": "2021-10-21 14:27:09.773165",
"modified": "2023-09-18 12:23:34.266895",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Service Level Agreement Fulfilled On Status",
Expand All @@ -28,5 +28,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
3 changes: 1 addition & 2 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
{
"fieldname": "on_hold_since",
"fieldtype": "Datetime",
"hidden": 1,
"label": "On Hold Since",
"read_only": 1
},
Expand Down Expand Up @@ -369,7 +368,7 @@
"icon": "fa fa-issue",
"idx": 61,
"links": [],
"modified": "2023-08-23 17:09:32.958800",
"modified": "2023-09-18 13:04:58.499150",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Ticket",
Expand Down
5 changes: 5 additions & 0 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def before_validate(self):
self.set_contact()
self.set_customer()
self.set_priority()
self.set_first_responded_on()
self.apply_escalation_rule()
self.set_sla()

Expand Down Expand Up @@ -221,6 +222,10 @@ def set_priority(self):
or DEFAULT_TICKET_PRIORITY
)

def set_first_responded_on(self):
if self.status == "Replied" and not self.first_responded_on:
self.first_responded_on = frappe.utils.now_datetime()

def validate_ticket_type(self):
settings = frappe.get_doc("HD Settings")
if settings.is_ticket_type_mandatory and not self.ticket_type:
Expand Down

0 comments on commit ba1a671

Please sign in to comment.