Skip to content

Commit

Permalink
Merge pull request #28550 from nextchamp-saqib/fix-sla
Browse files Browse the repository at this point in the history
refactor(SLA): Application of SLA and its fields
  • Loading branch information
nextchamp-saqib authored Dec 13, 2021
2 parents 6fa66a4 + 2f7d8ac commit 7d0a3e4
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 386 deletions.
5 changes: 2 additions & 3 deletions erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
},
"Communication": {
"on_update": [
"erpnext.support.doctype.service_level_agreement.service_level_agreement.update_hold_time",
"erpnext.support.doctype.service_level_agreement.service_level_agreement.on_communication_update",
"erpnext.support.doctype.issue.issue.set_first_response_time"
]
},
Expand Down Expand Up @@ -343,8 +343,7 @@
"erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.automatic_synchronization",
"erpnext.projects.doctype.project.project.hourly_reminder",
"erpnext.projects.doctype.project.project.collect_project_status",
"erpnext.hr.doctype.shift_type.shift_type.process_auto_attendance_for_all_shifts",
"erpnext.support.doctype.service_level_agreement.service_level_agreement.set_service_level_agreement_variance"
"erpnext.hr.doctype.shift_type.shift_type.process_auto_attendance_for_all_shifts"
],
"hourly_long": [
"erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.repost_entries"
Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ erpnext.patches.v13_0.update_category_in_ltds_certificate
erpnext.patches.v13_0.create_pan_field_for_india #2
erpnext.patches.v14_0.delete_hub_doctypes
erpnext.patches.v13_0.create_ksa_vat_custom_fields
erpnext.patches.v14_0.rename_ongoing_status_in_sla_documents
erpnext.patches.v14_0.migrate_crm_settings
erpnext.patches.v13_0.rename_ksa_qr_field
erpnext.patches.v13_0.disable_ksa_print_format_for_others
Expand Down
27 changes: 27 additions & 0 deletions erpnext/patches/v14_0/rename_ongoing_status_in_sla_documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import frappe


def execute():
active_sla_documents = [sla.document_type for sla in frappe.get_all("Service Level Agreement", fields=["document_type"])]

for doctype in active_sla_documents:
doctype = frappe.qb.DocType(doctype)
try:
frappe.qb.update(
doctype
).set(
doctype.agreement_status, 'First Response Due'
).where(
doctype.first_responded_on.isnull()
).run()

frappe.qb.update(
doctype
).set(
doctype.agreement_status, 'Resolution Due'
).where(
doctype.agreement_status == 'Ongoing'
).run()

except Exception:
frappe.log_error(title='Failed to Patch SLA Status')
15 changes: 8 additions & 7 deletions erpnext/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ $(document).on('app_ready', function() {

refresh: function(frm) {
if (frm.doc.status !== 'Closed' && frm.doc.service_level_agreement
&& frm.doc.agreement_status === 'Ongoing') {
&& ['First Response Due', 'Resolution Due'].includes(frm.doc.agreement_status)) {
frappe.call({
'method': 'frappe.client.get',
args: {
Expand Down Expand Up @@ -888,8 +888,8 @@ $(document).on('app_ready', function() {
function set_time_to_resolve_and_response(frm, apply_sla_for_resolution) {
frm.dashboard.clear_headline();

let time_to_respond = get_status(frm.doc.response_by_variance);
if (!frm.doc.first_responded_on && frm.doc.agreement_status === 'Ongoing') {
let time_to_respond = get_status(frm.doc.response_by);
if (!frm.doc.first_responded_on) {
time_to_respond = get_time_left(frm.doc.response_by, frm.doc.agreement_status);
}

Expand All @@ -903,8 +903,8 @@ function set_time_to_resolve_and_response(frm, apply_sla_for_resolution) {


if (apply_sla_for_resolution) {
let time_to_resolve = get_status(frm.doc.resolution_by_variance);
if (!frm.doc.resolution_date && frm.doc.agreement_status === 'Ongoing') {
let time_to_resolve = get_status(frm.doc.resolution_by);
if (!frm.doc.resolution_date) {
time_to_resolve = get_time_left(frm.doc.resolution_by, frm.doc.agreement_status);
}

Expand All @@ -928,8 +928,9 @@ function get_time_left(timestamp, agreement_status) {
return {'diff_display': diff_display, 'indicator': indicator};
}

function get_status(variance) {
if (variance > 0) {
function get_status(timestamp) {
const time_left = moment(timestamp).diff(moment());
if (time_left >= 0) {
return {'diff_display': 'Fulfilled', 'indicator': 'green'};
} else {
return {'diff_display': 'Failed', 'indicator': 'red'};
Expand Down
26 changes: 4 additions & 22 deletions erpnext/support/doctype/issue/issue.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
"service_level_section",
"service_level_agreement",
"response_by",
"response_by_variance",
"reset_service_level_agreement",
"cb",
"agreement_status",
"resolution_by",
"resolution_by_variance",
"service_level_agreement_creation",
"on_hold_since",
"total_hold_time",
Expand Down Expand Up @@ -123,7 +121,6 @@
"search_index": 1
},
{
"default": "Medium",
"fieldname": "priority",
"fieldtype": "Link",
"in_list_view": 1,
Expand Down Expand Up @@ -318,22 +315,6 @@
"fieldtype": "Check",
"label": "Via Customer Portal"
},
{
"depends_on": "eval: doc.service_level_agreement && doc.status != 'Replied';",
"fieldname": "response_by_variance",
"fieldtype": "Duration",
"hide_seconds": 1,
"label": "Response By Variance",
"read_only": 1
},
{
"depends_on": "eval: doc.service_level_agreement && doc.status != 'Replied';",
"fieldname": "resolution_by_variance",
"fieldtype": "Duration",
"hide_seconds": 1,
"label": "Resolution By Variance",
"read_only": 1
},
{
"fieldname": "service_level_agreement_creation",
"fieldtype": "Datetime",
Expand Down Expand Up @@ -391,12 +372,12 @@
"read_only": 1
},
{
"default": "Ongoing",
"default": "First Response Due",
"depends_on": "eval: doc.service_level_agreement",
"fieldname": "agreement_status",
"fieldtype": "Select",
"label": "Service Level Agreement Status",
"options": "Ongoing\nFulfilled\nFailed",
"options": "First Response Due\nResolution Due\nFulfilled\nFailed",
"read_only": 1
},
{
Expand All @@ -410,10 +391,11 @@
"icon": "fa fa-ticket",
"idx": 7,
"links": [],
"modified": "2021-06-10 03:22:27.098898",
"modified": "2021-11-24 13:13:10.276630",
"modified_by": "Administrator",
"module": "Support",
"name": "Issue",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator",
"permissions": [
{
Expand Down
4 changes: 1 addition & 3 deletions erpnext/support/doctype/issue/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ def split_issue(self, subject, communication_id):
if replicated_issue.service_level_agreement:
replicated_issue.service_level_agreement_creation = now_datetime()
replicated_issue.service_level_agreement = None
replicated_issue.agreement_status = "Ongoing"
replicated_issue.agreement_status = "First Response Due"
replicated_issue.response_by = None
replicated_issue.response_by_variance = None
replicated_issue.resolution_by = None
replicated_issue.resolution_by_variance = None
replicated_issue.reset_issue_metrics()

frappe.get_doc(replicated_issue).insert()
Expand Down
1 change: 0 additions & 1 deletion erpnext/support/doctype/issue/issue_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ frappe.listview_settings['Issue'] = {
},
get_indicator: function(doc) {
if (doc.status === 'Open') {
if (!doc.priority) doc.priority = 'Medium';
const color = {
'Low': 'yellow',
'Medium': 'orange',
Expand Down
Loading

0 comments on commit 7d0a3e4

Please sign in to comment.