'alten' stand wieder hergestellt

This commit is contained in:
Johannes Nickel 2013-06-12 16:57:29 +02:00
parent c239d32f1c
commit 26445e01e3
2 changed files with 206 additions and 1 deletions

View file

@ -610,7 +610,9 @@ class Ticket < ApplicationModel
# first response # first response
if sla_selected.first_response_time if sla_selected.first_response_time
self.first_response_escal_date = TimeCalculation.dest_time( created_at, sla_selected.first_response_time, sla_selected.data, sla_selected.timezone ) self.first_response_escal_date = TimeCalculation.dest_time( created_at, sla_selected.first_response_time, sla_selected.data, sla_selected.timezone )
extended_escalation = escalation_suspend( self.first_response_escal_date, 'relative', sla_selected.timezone)
self.first_response_escal_date = TimeCalculation.dest_time( self.first_response_escal_date, extended_escalation.to_i, sla_selected.timezone)
# set ticket escalation # set ticket escalation
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.first_response_escal_date, self.first_response ) self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.first_response_escal_date, self.first_response )
end end
@ -700,6 +702,95 @@ class Ticket < ApplicationModel
# delete articles # delete articles
self.articles.destroy_all self.articles.destroy_all
end end
#type could be:
# real - time without supsend state
# relative - only suspend time
def escalation_suspend (end_time, type, sla_timezone)
sum_temp = 0
total_time = 0
#get history for ticket
history_list = History.history_list( 'Ticket', self.id, 'Ticket' )
#loop through hist. changes and get time
last_state = nil
last_state_change = nil
last_state_is_pending = false
history_list.each { |history_item|
# ignore if it isn't a state change
next if history_item['history_attribute'] != 'ticket_state'
# ignore all older state changes after first_response
next if last_state_change && last_state_change > self.first_response
# if created_at is later then first_response, use first_response as last time
if history_item['created_at'] > self.first_response
history_item['created_at'] = self.first_response
end
# get initial state and time
if !last_state
last_state = history_item['value_from']
last_state_change = self.created_at
end
# use time if ticket got from e. g. open to pending
if history_item['value_from'] != 'pending' && history_item['value_to'] == 'pending'
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_timezone)
puts 'Diff count !=pending -> ==pending ' + diff.to_s
sum_temp = sum_temp + diff
total_time = total_time + diff
last_state_is_pending = true
# use time if ticket got from e. g. open to open
elsif history_item['value_from'] != 'pending' && history_item['value_to'] != 'pending'
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_timezone)
puts 'Diff count !=pending -> !=pending ' + diff.to_s
sum_temp = sum_temp + diff
total_time = total_time + diff
last_state_is_pending = false
elsif history_item['value_from'] == 'pending' && history_item['value_to'] != 'pending'
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_timezone)
puts 'Diff count !=pending -> !=pending ' + diff.to_s
total_time = total_time + diff
last_state_is_pending = false
# no pending state, do not count
else
puts "Diff do not count #{history_item['value_from']}->#{history_item['value_to']} -> #{history_item['created_at']}"
last_state_is_pending = false
end
# remember for next loop last state
last_state = history_item['value_to']
last_state_change = history_item['created_at']
}
# if last state isnt pending, count rest
if !last_state_is_pending && last_state_change && last_state_change < end_time
diff = TimeCalculation.business_time_diff( last_state_change, end_time, sla_timezone)
sum_temp = sum_temp + diff
total_time = total_time + diff
end
# if we have not had any state change
if !last_state_change
puts self.created_at.to_s + ' ' + end_time.to_s + ' ' + sla_timezone.to_s
diff = TimeCalculation.business_time_diff( self.created_at, end_time, sla_timezone)
sum_temp = sum_temp + diff
total_time = total_time + diff
end
puts total_time
#return sum
if (type == 'real')
return sum_temp
elsif (type == 'relative')
return total_time - sum_temp
else
return nil
end
end
class Number class Number
end end

View file

@ -569,6 +569,120 @@ class TicketTest < ActiveSupport::TestCase
delete = ticket.destroy delete = ticket.destroy
assert( delete, "ticket destroy" ) assert( delete, "ticket destroy" )
ticket = Ticket.create(
:title => 'some title äöüß3',
:group => Group.lookup( :name => 'Users'),
:customer_id => 2,
:ticket_state => Ticket::State.lookup( :name => 'new' ),
:ticket_priority => Ticket::Priority.lookup( :name => '2 normal' ),
:created_at => '2013-06-04 09:00:00 UTC',
:updated_at => '2013-06-04 09:00:00 UTC',
:updated_by_id => 1,
:created_by_id => 1,
)
assert( ticket, 'ticket created' )
# set ticket at 10:00 to pending
History.history_create(
:history_type => 'updated',
:history_object => 'Ticket',
:history_attribute => 'ticket_state',
:o_id => ticket.id,
:id_to => 3,
:id_from => 2,
:value_from => 'open',
:value_to => 'pending',
:created_by_id => 1,
:created_at => '2013-06-04 10:00:00',
:updated_at => '2013-06-04 10:00:00'
)
# set ticket at 10:30 to open
History.history_create(
:history_type => 'updated',
:history_object => 'Ticket',
:history_attribute => 'ticket_state',
:o_id => ticket.id,
:id_to => 2,
:id_from => 3,
:value_from => 'pending',
:value_to => 'open',
:created_by_id => 1,
:created_at => '2013-06-04 10:30:00',
:updated_at => '2013-06-04 10:30:00'
)
# set ticket from 11:00 to pending
History.history_create(
:history_type => 'updated',
:history_object => 'Ticket',
:history_attribute => 'ticket_state',
:o_id => ticket.id,
:id_to => 3,
:id_from => 2,
:value_from => 'open',
:value_to => 'pending',
:created_by_id => 1,
:created_at => '2013-06-04 11:00:00',
:updated_at => '2013-06-04 11:00:00'
)
# set first response in time
ticket.update_attributes(
:first_response => '2013-06-04 10:45:00 UTC',
)
# set ticket from 11:30 to closed
History.history_create(
:history_type => 'updated',
:history_object => 'Ticket',
:history_attribute => 'ticket_state',
:o_id => ticket.id,
:id_to => 3,
:id_from => 2,
:value_from => 'pending',
:value_to => 'closed',
:created_by_id => 1,
:created_at => '2013-06-04 12:00:00',
:updated_at => '2013-06-04 12:00:00'
)
ticket.update_attributes(
:close_time => '2013-06-04 12:00:00 UTC',
)
# set sla's for timezone "Europe/Berlin" summertime (+2), so UTC times are 7:00-16:00
sla = Sla.create(
:name => 'test sla 1',
:condition => {},
:data => {
"Mon"=>"Mon", "Tue"=>"Tue", "Wed"=>"Wed", "Thu"=>"Thu", "Fri"=>"Fri", "Sat"=>"Sat", "Sun"=>"Sun",
"beginning_of_workday" => "9:00",
"end_of_workday" => "18:00",
},
:timezone => 'Europe/Berlin',
:first_response_time => 120,
:update_time => 180,
:close_time => 240,
:active => true,
:updated_by_id => 1,
:created_by_id => 1,
)
ticket = Ticket.find(ticket.id)
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 12:00:00 UTC', 'ticket.escalation_time verify 1' ) #check escal. time because first resp. is already done
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
#assert_equal( ticket.first_response_in_min, 75, 'ticket.first_response_in_min verify 3' )
#assert_equal( ticket.first_response_diff_in_min, 45, 'ticket.first_response_diff_in_min verify 3' )
#assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
#assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
#assert_equal( ticket.close_time_in_min, 90, 'ticket.first_response_in_min verify 3' )
#assert_equal( ticket.close_time_diff_in_min, 150, 'ticket.first_response_diff_in_min verify 3' )
delete = sla.destroy
assert( delete, "sla destroy" )
delete = ticket.destroy
assert( delete, "ticket destroy" )
end end
end end