Also set close time on ticket creation with close state.
This commit is contained in:
parent
2c505a5601
commit
ec8f36238c
1 changed files with 29 additions and 20 deletions
|
@ -1,24 +1,33 @@
|
||||||
class Observer::Ticket::CloseTime < ActiveRecord::Observer
|
class Observer::Ticket::CloseTime < ActiveRecord::Observer
|
||||||
observe 'ticket'
|
observe 'ticket'
|
||||||
|
|
||||||
def after_update(record)
|
def after_create(record)
|
||||||
# puts 'check close time'
|
_check(record)
|
||||||
|
|
||||||
# return if we run import mode
|
|
||||||
return if Setting.get('import_mode')
|
|
||||||
|
|
||||||
# check if close_time is already set
|
|
||||||
return true if record.close_time
|
|
||||||
|
|
||||||
# check if ticket is closed now
|
|
||||||
ticket_state = Ticket::State.find( record.ticket_state_id )
|
|
||||||
ticket_state_type = Ticket::StateType.find( ticket_state.ticket_state_type_id )
|
|
||||||
return true if ticket_state_type.name != 'closed'
|
|
||||||
|
|
||||||
# set close_time
|
|
||||||
record.close_time = Time.now
|
|
||||||
|
|
||||||
# save ticket
|
|
||||||
record.save
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def after_update(record)
|
||||||
|
_check(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def _check(record)
|
||||||
|
# puts 'check close time'
|
||||||
|
|
||||||
|
# return if we run import mode
|
||||||
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
|
# check if close_time is already set
|
||||||
|
return true if record.close_time
|
||||||
|
|
||||||
|
# check if ticket is closed now
|
||||||
|
ticket_state = Ticket::State.find( record.ticket_state_id )
|
||||||
|
ticket_state_type = Ticket::StateType.find( ticket_state.ticket_state_type_id )
|
||||||
|
return true if ticket_state_type.name != 'closed'
|
||||||
|
|
||||||
|
# set close_time
|
||||||
|
record.close_time = Time.now
|
||||||
|
|
||||||
|
# save ticket
|
||||||
|
record.save
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue