trabajo-afectivo/app/models/ticket/sets_close_time.rb

33 lines
780 B
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
# Adds close time (if missing) when tickets are closed.
module Ticket::SetsCloseTime
extend ActiveSupport::Concern
2012-11-18 10:56:48 +00:00
included do
before_create :ticket_set_close_time
before_update :ticket_set_close_time
end
2012-11-18 10:56:48 +00:00
private
def ticket_set_close_time
# return if we run import mode
return true if Setting.get('import_mode')
2012-11-18 10:56:48 +00:00
# check if close_at is already set
return true if close_at
2012-11-18 10:56:48 +00:00
# check if ticket is closed now
return true if !state_id
state = Ticket::State.lookup(id: state_id)
2016-03-08 06:32:58 +00:00
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_at
self.close_at = Time.zone.now
end
end