trabajo-afectivo/app/models/observer/ticket/close_time.rb

36 lines
798 B
Ruby
Raw Normal View History

2014-02-03 19:23:00 +00:00
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
2012-11-18 10:56:48 +00:00
class Observer::Ticket::CloseTime < ActiveRecord::Observer
observe 'ticket'
def after_create(record)
_check(record)
end
2012-11-18 10:56:48 +00:00
def after_update(record)
_check(record)
end
2012-11-18 10:56:48 +00:00
private
def _check(record)
# puts 'check close time'
# return if we run import mode
return if Setting.get('import_mode')
2012-11-18 10:56:48 +00:00
# check if close_time is already set
return true if record.close_time
2012-11-18 10:56:48 +00:00
# check if ticket is closed now
state = Ticket::State.lookup( :id => record.state_id )
state_type = Ticket::StateType.lookup( :id => state.state_type_id )
return true if state_type.name != 'closed'
2012-11-18 10:56:48 +00:00
# set close_time
record.close_time = Time.now
# save ticket
record.save
end
end