From 1fb3ac5133b01d8189b8bd10a87de5041c9bb1ee Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 30 Oct 2015 10:14:34 +0100 Subject: [PATCH] Improved escalation update time calculation. --- app/models/ticket/escalation.rb | 20 ++++++++--- test/unit/ticket_sla_test.rb | 60 +++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 2a5bbfc7d..5ad3bf551 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -82,6 +82,9 @@ returns } } config.hours = hours + if !hours || hours.empty? + fail "No congifure hours found in calendar #{calendar.inspect}" + end # get holidays holidays = [] @@ -123,11 +126,18 @@ returns # update time # calculate escalation - last_update = last_contact_agent - if !last_update + if !last_contact_customer && !last_contact_agent last_update = created_at + elsif !last_contact_customer && last_contact_agent + last_update = last_contact_agent + elsif last_contact_customer && !last_contact_agent + last_update = last_contact_customer + elsif last_contact_agent > last_contact_customer + last_update = last_contact_agent + elsif last_contact_agent < last_contact_customer + last_update = last_contact_customer end - if sla.update_time + if sla.update_time && last_update self.update_time_escal_date = biz.time(sla.update_time, :minutes).after(last_update) pending_time = pending_minutes(last_update, update_time_escal_date, biz) if pending_time && pending_time > 0 @@ -139,8 +149,8 @@ returns end # get update time in min - if last_contact_agent - self.update_time_in_min = pending_minutes(created_at, last_contact_agent, biz, 'business_minutes') + if last_update && last_update != created_at + self.update_time_in_min = pending_minutes(created_at, last_update, biz, 'business_minutes') end # set sla time diff --git a/test/unit/ticket_sla_test.rb b/test/unit/ticket_sla_test.rb index 80186ec21..7d4f69d8c 100644 --- a/test/unit/ticket_sla_test.rb +++ b/test/unit/ticket_sla_test.rb @@ -226,20 +226,58 @@ class TicketSlaTest < ActiveSupport::TestCase assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 6' ) assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 6' ) + # set update time over time + ticket.update_attributes( + last_contact_customer: '2013-03-21 12:05:00 UTC', + ) + assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_time verify 6' ) + + assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 6' ) + assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 6' ) + assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6' ) + assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6' ) + + assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:05:00 UTC', 'ticket.update_time_escal_date verify 6' ) + assert_equal( ticket.update_time_in_min, 155, 'ticket.update_time_in_min verify 6' ) + assert_equal( ticket.update_time_diff_in_min, -35, 'ticket.update_time_diff_in_min verify 6' ) + + assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 6' ) + assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 6' ) + assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 6' ) + + # set update time over time + ticket.update_attributes( + last_contact_agent: '2013-03-21 12:10:00 UTC', + ) + assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_time verify 6' ) + + assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 6' ) + assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 6' ) + assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 6' ) + assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 6' ) + + assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_time_escal_date verify 6' ) + assert_equal( ticket.update_time_in_min, 160, 'ticket.update_time_in_min verify 6' ) + assert_equal( ticket.update_time_diff_in_min, -40, 'ticket.update_time_diff_in_min verify 6' ) + + assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 6' ) + assert_equal( ticket.close_time_in_min, nil, 'ticket.close_time_in_min verify 6' ) + assert_equal( ticket.close_time_diff_in_min, nil, 'ticket.close_time_diff_in_min verify 6' ) + # set close time in time ticket.update_attributes( close_time: '2013-03-21 11:30:00 UTC', ) - assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.escalation_time verify 7' ) + assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_time verify 7' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 7' ) assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 7' ) assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 7' ) assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 7' ) - assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 7' ) - assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 7' ) - assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 7' ) + assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_time_escal_date verify 7' ) + assert_equal( ticket.update_time_in_min, 160, 'ticket.update_time_in_min verify 7' ) + assert_equal( ticket.update_time_diff_in_min, -40, 'ticket.update_time_diff_in_min verify 7' ) assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 7' ) assert_equal( ticket.close_time_in_min, 120, 'ticket.close_time_in_min verify 7' ) @@ -249,16 +287,16 @@ class TicketSlaTest < ActiveSupport::TestCase ticket.update_attributes( close_time: '2013-03-21 13:00:00 UTC', ) - assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.escalation_time verify 8' ) + assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_time verify 8' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 8' ) assert_equal( ticket.first_response.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.first_response verify 8' ) assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 8' ) assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 8' ) - assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 8' ) - assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 8' ) - assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 8' ) + assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_time_escal_date verify 8' ) + assert_equal( ticket.update_time_in_min, 160, 'ticket.update_time_in_min verify 8' ) + assert_equal( ticket.update_time_diff_in_min, -40, 'ticket.update_time_diff_in_min verify 8' ) assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 8' ) assert_equal( ticket.close_time_in_min, 210, 'ticket.close_time_in_min verify 8' ) @@ -275,9 +313,9 @@ class TicketSlaTest < ActiveSupport::TestCase assert_equal( ticket.first_response_in_min, 270, 'ticket.first_response_in_min verify 9' ) assert_equal( ticket.first_response_diff_in_min, -210, 'ticket.first_response_diff_in_min verify 9' ) - assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 9' ) - assert_equal( ticket.update_time_in_min, 150, 'ticket.update_time_in_min verify 9' ) - assert_equal( ticket.update_time_diff_in_min, -30, 'ticket.update_time_diff_in_min verify 9' ) + assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.update_time_escal_date verify 9' ) + assert_equal( ticket.update_time_in_min, 160, 'ticket.update_time_in_min verify 9' ) + assert_equal( ticket.update_time_diff_in_min, -40, 'ticket.update_time_diff_in_min verify 9' ) assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.close_time_escal_date verify 9' ) assert_equal( ticket.close_time_in_min, 210, 'ticket.close_time_in_min verify 9' )