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

35 lines
965 B
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Observer::Ticket::ResetNewState < ActiveRecord::Observer
observe 'ticket::_article'
def after_create(record)
# return if we run import mode
return if Setting.get('import_mode')
# if article in internal
return true if record.internal
# if sender is agent
2016-03-08 06:32:58 +00:00
return true if Ticket::Article::Sender.lookup(id: record.sender_id).name != 'Agent'
# if article is a message to customer
2016-03-08 06:32:58 +00:00
return true if !Ticket::Article::Type.lookup(id: record.type_id).communication
# if current ticket state is still new
2016-03-08 06:32:58 +00:00
ticket = Ticket.lookup(id: record.ticket_id)
new_state = Ticket::State.find_by(default_create: true)
return true if ticket.state_id != new_state.id
state = Ticket::State.find_by(default_follow_up: true)
return if !state
# set ticket to open
ticket.state_id = state.id
# save ticket
ticket.save
end
end