2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
# Adds close time (if missing) when tickets are closed.
|
|
|
|
module Ticket::SetsCloseTime
|
|
|
|
extend ActiveSupport::Concern
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
included do
|
|
|
|
before_create :ticket_set_close_time
|
|
|
|
before_update :ticket_set_close_time
|
2012-12-30 11:48:53 +00:00
|
|
|
end
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
private
|
2015-05-01 12:31:46 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
def ticket_set_close_time
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# return if we run import mode
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if Setting.get('import_mode')
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2016-09-14 07:15:30 +00:00
|
|
|
# check if close_at is already set
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if close_at
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# check if ticket is closed now
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if !state_id
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
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)
|
2014-06-08 22:01:20 +00:00
|
|
|
return true if state_type.name != 'closed'
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2016-09-14 07:15:30 +00:00
|
|
|
# set close_at
|
2021-03-01 08:18:40 +00:00
|
|
|
self.close_at = Time.zone.now
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|
|
|
|
end
|