Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ux): allow empty sla #1600

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions desk/src/pages/ticket/TicketDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,33 @@
{{ data.customer }}
</span>
</div>
<div class="space-y-1.5">
<span class="block text-sm text-gray-700">First response</span>
<span class="mr-2 font-medium text-gray-900">
<div
v-if="data.first_responded_on || data.response_by"
class="space-y-1.5"
>
<div class="text-sm text-gray-700">First response</div>
<div class="mr-2 inline-block font-medium text-gray-900">
{{ dayjs(data.first_responded_on || data.response_by).short() }}
</div>
<span v-if="data.response_by">
<Badge
v-if="!data.first_responded_on"
label="Due"
theme="orange"
variant="outline"
/>
<Badge
v-else-if="
dayjs(data.first_responded_on).isBefore(
dayjs(data.response_by)
)
"
label="Fulfilled"
theme="green"
variant="outline"
/>
<Badge v-else label="Failed" theme="red" variant="outline" />
</span>
<Badge
v-if="!data.first_responded_on"
label="Due"
theme="orange"
variant="outline"
/>
<Badge
v-else-if="
dayjs(data.first_responded_on).isBefore(dayjs(data.response_by))
"
label="Fulfilled"
theme="green"
variant="outline"
/>
<Badge v-else label="Failed" theme="red" variant="outline" />
</div>
<div
v-if="data.resolution_date || data.resolution_by"
Expand Down
1 change: 1 addition & 0 deletions desk/src/pages/tickets/TicketsAgentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</template>
<template #agreement_status="{ data }">
<Badge
v-if="data.agreement_status"
:label="data.agreement_status"
:theme="slaStatusColorMap[data.agreement_status]"
variant="outline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class HDServiceLevelAgreement(Document):
doctype_ticket = "HD Ticket"

Check warning on line 20 in helpdesk/helpdesk/doctype/hd_service_level_agreement/hd_service_level_agreement.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_service_level_agreement/hd_service_level_agreement.py#L20

Added line #L20 was not covered by tests

def validate(self):
self.validate_priorities() # To refactor
Expand Down Expand Up @@ -95,10 +95,10 @@
if not self.condition:
return
try:
temp_doc = frappe.new_doc(self.doctype_ticket)

Check warning on line 98 in helpdesk/helpdesk/doctype/hd_service_level_agreement/hd_service_level_agreement.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_service_level_agreement/hd_service_level_agreement.py#L98

Added line #L98 was not covered by tests
frappe.safe_eval(self.condition, None, get_context(temp_doc))
except Exception as e:
frappe.throw(

Check warning on line 101 in helpdesk/helpdesk/doctype/hd_service_level_agreement/hd_service_level_agreement.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_service_level_agreement/hd_service_level_agreement.py#L101

Added line #L101 was not covered by tests
_("The Condition '{0}' is invalid: {1}").format(self.condition, str(e))
)

Expand All @@ -116,11 +116,6 @@
}
)

def on_trash(self):
if self.service_level == "Default":
text = _("The Default HD Service Level Agreement cannot be deleted")
frappe.throw(text, frappe.PermissionError)

def apply(self, doc: Document):
self.handle_new(doc)
self.handle_status(doc)
Expand Down
7 changes: 3 additions & 4 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"actions": [],
"allow_import": 1,
"autoname": "autoincrement",
"creation": "2022-03-02 03:10:19.254460",
"creation": "2023-10-17 14:27:11.078679",
"doctype": "DocType",
"document_type": "Setup",
"email_append_to": 1,
Expand Down Expand Up @@ -176,12 +176,11 @@
"read_only": 1
},
{
"default": "First Response Due",
"depends_on": "eval: doc.sla",
"fieldname": "agreement_status",
"fieldtype": "Select",
"label": "SLA Status",
"options": "First Response Due\nResolution Due\nFailed\nFulfilled\nPaused",
"options": "\nFirst Response Due\nResolution Due\nFailed\nFulfilled\nPaused",
"read_only": 1
},
{
Expand Down Expand Up @@ -380,7 +379,7 @@
"icon": "fa fa-issue",
"idx": 61,
"links": [],
"modified": "2023-10-08 23:24:56.917977",
"modified": "2023-10-17 16:20:41.301974",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Ticket",
Expand Down
10 changes: 8 additions & 2 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
self.set_contact()
self.set_customer()
self.set_priority()
self.set_first_responded_on()

Check warning on line 169 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L169

Added line #L169 was not covered by tests
self.set_feedback_values()
self.apply_escalation_rule()
self.set_sla()
Expand Down Expand Up @@ -230,9 +230,9 @@
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()

Check warning on line 235 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L233-L235

Added lines #L233 - L235 were not covered by tests

def set_feedback_values(self):
if not self.feedback:
Expand Down Expand Up @@ -713,12 +713,18 @@
self.assign_agent(escalation_rule.to_agent)

def set_sla(self):
"""
Find an SLA to apply to this ticket.
"""
if sla := get_sla(self):
self.sla = sla.name

def apply_sla(self):
sla = frappe.get_doc("HD Service Level Agreement", self.sla)
sla.apply(self)
"""
Apply SLA if set.
"""
if sla := frappe.get_last_doc("HD Service Level Agreement", {"name": self.sla}):
sla.apply(self)

Check warning on line 727 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L726-L727

Added lines #L726 - L727 were not covered by tests

# `on_communication_update` is a special method exposed from `Communication` doctype.
# It is called when a communication is updated. Beware of changes as this effectively
Expand All @@ -727,8 +733,8 @@
def on_communication_update(self, c):
# If communication is incoming, then it is a reply from customer, and ticket must
# be reopened.
if c.sent_or_received == "Received":
self.status = "Open"

Check warning on line 737 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L736-L737

Added lines #L736 - L737 were not covered by tests
# Fetch description from communication if not set already. This might not be needed
# anymore as a communication is created when a ticket is created.
self.description = self.description or c.content
Expand Down
13 changes: 12 additions & 1 deletion helpdesk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
frappe.throw(f"Insufficient Permission for {doctype}", frappe.PermissionError)


def is_admin(user: str = None) -> bool:

Check warning on line 25 in helpdesk/utils.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/utils.py#L25

Added line #L25 was not covered by tests
"""
Check whether `user` is an admin

:param user: User to check against, defaults to current user
:return: Whether `user` is an admin
"""
user = user or frappe.session.user
return user == "Administrator"

Check warning on line 33 in helpdesk/utils.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/utils.py#L32-L33

Added lines #L32 - L33 were not covered by tests


def is_agent(user: str = None) -> bool:
"""
Check whether `user` is an agent
Expand All @@ -30,7 +41,7 @@
:return: Whether `user` is an agent
"""
user = user or frappe.session.user
return bool(frappe.db.exists("HD Agent", {"name": user}))
return is_admin() or bool(frappe.db.exists("HD Agent", {"name": user}))

Check warning on line 44 in helpdesk/utils.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/utils.py#L44

Added line #L44 was not covered by tests


def publish_event(event: str, data: dict, user: str = None):
Expand Down
Loading