Skip to content

Commit

Permalink
Merge pull request #1600 from ssiyad/fix/ux/allow_empty_sla
Browse files Browse the repository at this point in the history
fix(ux): allow empty sla
  • Loading branch information
ssiyad authored Oct 17, 2023
2 parents c6a2f4f + 2d07252 commit c89adc2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
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 @@ -116,11 +116,6 @@ def get_hd_service_level_agreement_priority(self, priority):
}
)

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 @@ -713,12 +713,18 @@ def apply_escalation_rule(self):
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)

# `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 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 @@ def check_permissions(doctype, parent):
frappe.throw(f"Insufficient Permission for {doctype}", frappe.PermissionError)


def is_admin(user: str = None) -> bool:
"""
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"


def is_agent(user: str = None) -> bool:
"""
Check whether `user` is an agent
Expand All @@ -30,7 +41,7 @@ def is_agent(user: str = None) -> bool:
: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}))


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

0 comments on commit c89adc2

Please sign in to comment.