From a2aaa8c2cec9a2b0c0ff4c2050c8cfe2cf685a8f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 13 Jun 2013 17:39:22 +0200 Subject: [PATCH] Small improvement to make escalation_calculation() smaller. --- app/models/ticket.rb | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index bbf211a10..f1c99eaa5 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -755,11 +755,7 @@ class Ticket < ApplicationModel # use time if ticket got from e. g. open to pending if history_item['value_from'] != 'pending' && history_item['value_to'] == 'pending' - if sla_selected - diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'],sla_selected.data, sla_selected.timezone) - else - diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'] ) - end + diff = self.escalation_time_diff( last_state_change, history_item['created_at'], sla_selected ) puts "Diff count !=pending -> ==pending #{diff.to_s} - #{last_state_change} - #{history_item['created_at']}" total_time_without_pending = total_time_without_pending + diff total_time = total_time + diff @@ -767,21 +763,13 @@ class Ticket < ApplicationModel # use time if ticket got from e. g. open to open elsif history_item['value_from'] != 'pending' && history_item['value_to'] != 'pending' - if sla_selected - diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_selected.data, sla_selected.timezone) - else - diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'] ) - end + diff = self.escalation_time_diff( last_state_change, history_item['created_at'], sla_selected ) puts "Diff count !=pending -> !=pending #{diff.to_s} - #{last_state_change} - #{history_item['created_at']}" total_time_without_pending = total_time_without_pending + diff total_time = total_time + diff last_state_is_pending = false elsif history_item['value_from'] == 'pending' && history_item['value_to'] != 'pending' - if sla_selected - diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_selected.data, sla_selected.timezone) - else - diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'] ) - end + diff = self.escalation_time_diff( last_state_change, history_item['created_at'], sla_selected ) puts "Diff not count ==pending -> !=pending #{diff.to_s} - #{last_state_change} - #{history_item['created_at']}" total_time = total_time + diff last_state_is_pending = false @@ -798,11 +786,7 @@ class Ticket < ApplicationModel # if last state isnt pending, count rest if !last_state_is_pending && last_state_change && last_state_change < end_time - if sla_selected - diff = TimeCalculation.business_time_diff( last_state_change, end_time, sla_selected.data, sla_selected.timezone) - else - diff = TimeCalculation.business_time_diff( last_state_change, end_time ) - end + diff = self.escalation_time_diff( last_state_change, end_time, sla_selected ) puts "Diff count last state was not pending #{diff.to_s} - #{last_state_change} - #{end_time}" total_time_without_pending = total_time_without_pending + diff total_time = total_time + diff @@ -810,11 +794,7 @@ class Ticket < ApplicationModel # if we have not had any state change if !last_state_change - if sla_selected - diff = TimeCalculation.business_time_diff( start_time, end_time, sla_selected.data, sla_selected.timezone) - else - diff = TimeCalculation.business_time_diff( start_time, end_time ) - end + diff = self.escalation_time_diff( start_time, end_time, sla_selected ) puts 'Diff state has not changed ' + diff.to_s total_time_without_pending = total_time_without_pending + diff total_time = total_time + diff @@ -831,6 +811,15 @@ class Ticket < ApplicationModel end end + def escalation_time_diff( start_time, end_time, sla_selected ) + if sla_selected + diff = TimeCalculation.business_time_diff( start_time, end_time, sla_selected.data, sla_selected.timezone) + else + diff = TimeCalculation.business_time_diff( start_time, end_time ) + end + diff + end + class Number end