Added support of timezones in escalation calculation.
This commit is contained in:
parent
7dd0208618
commit
3e3f268566
4 changed files with 126 additions and 12 deletions
|
@ -522,7 +522,7 @@ class Ticket < ApplicationModel
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def _escalation_calculation_get_sla
|
def _escalation_calculation_get_sla(time)
|
||||||
|
|
||||||
sla_selected = nil
|
sla_selected = nil
|
||||||
sla_list = Cache.get( 'SLA::List::Active' )
|
sla_list = Cache.get( 'SLA::List::Active' )
|
||||||
|
@ -559,7 +559,7 @@ class Ticket < ApplicationModel
|
||||||
|
|
||||||
# get and set calendar settings
|
# get and set calendar settings
|
||||||
if sla_selected
|
if sla_selected
|
||||||
TimeCalculation.config( sla_selected.data )
|
TimeCalculation.config( sla_selected.data, sla_selected.timezone, time )
|
||||||
end
|
end
|
||||||
return sla_selected
|
return sla_selected
|
||||||
end
|
end
|
||||||
|
@ -588,7 +588,7 @@ class Ticket < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
# get sla for ticket
|
# get sla for ticket
|
||||||
sla_selected = self._escalation_calculation_get_sla
|
sla_selected = self._escalation_calculation_get_sla(self.created_at)
|
||||||
|
|
||||||
# reset escalation if no sla is set
|
# reset escalation if no sla is set
|
||||||
if !sla_selected
|
if !sla_selected
|
||||||
|
|
|
@ -4,7 +4,25 @@ require 'business_time/core_ext/fixnum_minute'
|
||||||
require 'business_time/core_ext/time_fix'
|
require 'business_time/core_ext/time_fix'
|
||||||
|
|
||||||
module TimeCalculation
|
module TimeCalculation
|
||||||
def self.config(config)
|
def self.config(config, timezone, start_time)
|
||||||
|
time_diff = 0
|
||||||
|
if timezone
|
||||||
|
begin
|
||||||
|
time_diff = Time.parse(start_time.to_s).in_time_zone(timezone).utc_offset
|
||||||
|
rescue Exception => e
|
||||||
|
puts "ERROR: Can't fine tomezone #{timezone}"
|
||||||
|
puts e.inspect
|
||||||
|
puts e.backtrace
|
||||||
|
end
|
||||||
|
end
|
||||||
|
beginning_of_workday = Time.parse("1977-10-27 #{config['beginning_of_workday']}") + time_diff
|
||||||
|
if beginning_of_workday
|
||||||
|
config['beginning_of_workday'] = "#{beginning_of_workday.hour}:#{beginning_of_workday.min}"
|
||||||
|
end
|
||||||
|
end_of_workday = Time.parse("1977-10-27 #{config['end_of_workday']}") + time_diff
|
||||||
|
if end_of_workday
|
||||||
|
config['end_of_workday'] = "#{end_of_workday.hour}:#{end_of_workday.min}"
|
||||||
|
end
|
||||||
BusinessTime::Config.beginning_of_workday = config['beginning_of_workday']
|
BusinessTime::Config.beginning_of_workday = config['beginning_of_workday']
|
||||||
BusinessTime::Config.end_of_workday = config['end_of_workday']
|
BusinessTime::Config.end_of_workday = config['end_of_workday']
|
||||||
days = []
|
days = []
|
||||||
|
|
|
@ -432,4 +432,100 @@ class TicketTest < ActiveSupport::TestCase
|
||||||
delete = sla.destroy
|
delete = sla.destroy
|
||||||
assert( delete, "sla destroy" )
|
assert( delete, "sla destroy" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'ticket sla + timezone' do
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
delete = Sla.destroy_all
|
||||||
|
assert( delete, "sla destroy_all" )
|
||||||
|
delete = Ticket.destroy_all
|
||||||
|
assert( delete, "ticket destroy_all" )
|
||||||
|
|
||||||
|
ticket = Ticket.create(
|
||||||
|
:title => 'some title äöüß',
|
||||||
|
: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-03-21 09:30:00 UTC',
|
||||||
|
:updated_at => '2013-03-21 09:30:00 UTC',
|
||||||
|
:updated_by_id => 1,
|
||||||
|
:created_by_id => 1,
|
||||||
|
)
|
||||||
|
assert( ticket, "ticket created" )
|
||||||
|
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify' )
|
||||||
|
|
||||||
|
# set sla's for timezone "Europe/Berlin" (+1), so UTC times are 8:00-17: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-03-21 12:00:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 12:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 13:00:00 UTC', 'ticket.update_time_escal_date verify 1' )
|
||||||
|
assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 14:00:00 UTC', 'ticket.close_time_escal_date verify 1' )
|
||||||
|
|
||||||
|
delete = sla.destroy
|
||||||
|
assert( delete, "sla destroy" )
|
||||||
|
|
||||||
|
delete = ticket.destroy
|
||||||
|
assert( delete, "ticket destroy" )
|
||||||
|
|
||||||
|
ticket = Ticket.create(
|
||||||
|
:title => 'some title äöüß',
|
||||||
|
: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-10-21 09:30:00 UTC',
|
||||||
|
:updated_at => '2013-10-21 09:30:00 UTC',
|
||||||
|
:updated_by_id => 1,
|
||||||
|
:created_by_id => 1,
|
||||||
|
)
|
||||||
|
assert( ticket, "ticket created" )
|
||||||
|
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify' )
|
||||||
|
|
||||||
|
# set sla's for timezone "Europe/Berlin" (+1), so UTC times are 8:00-17: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-10-21 13:00:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 13:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-10-21 14:00:00 UTC', 'ticket.update_time_escal_date verify 1' )
|
||||||
|
assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-10-21 15:00:00 UTC', 'ticket.close_time_escal_date verify 1' )
|
||||||
|
|
||||||
|
delete = ticket.destroy
|
||||||
|
assert( delete, "ticket destroy" )
|
||||||
|
|
||||||
|
delete = sla.destroy
|
||||||
|
assert( delete, "sla destroy" )
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -89,7 +89,7 @@ class WorkingTimeTest < ActiveSupport::TestCase
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
tests.each { |test|
|
tests.each { |test|
|
||||||
TimeCalculation.config( test[:config] )
|
TimeCalculation.config( test[:config], nil, test[:start] )
|
||||||
diff = TimeCalculation.business_time_diff( test[:start], test[:end] )
|
diff = TimeCalculation.business_time_diff( test[:start], test[:end] )
|
||||||
assert_equal( diff, test[:diff], 'diff' )
|
assert_equal( diff, test[:diff], 'diff' )
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ class WorkingTimeTest < ActiveSupport::TestCase
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
tests.each { |test|
|
tests.each { |test|
|
||||||
TimeCalculation.config( test[:config] )
|
TimeCalculation.config( test[:config], nil, test[:start] )
|
||||||
dest_time = TimeCalculation.dest_time( test[:start] + ' UTC', test[:diff] )
|
dest_time = TimeCalculation.dest_time( test[:start] + ' UTC', test[:diff] )
|
||||||
assert_equal( dest_time.gmtime, Time.parse( test[:dest_time] + ' UTC' ), "dest time - #{test[:dest_time].to_s}" )
|
assert_equal( dest_time.gmtime, Time.parse( test[:dest_time] + ' UTC' ), "dest time - #{test[:dest_time].to_s}" )
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue