first_response.rb 931 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::FirstResponse < ActiveRecord::Observer
  3. observe 'ticket::_article'
  4. def after_create(record)
  5. # puts 'check first response'
  6. # return if we run import mode
  7. return if Setting.get('import_mode')
  8. # if article in internal
  9. return true if record.internal
  10. # if sender is not agent
  11. sender = Ticket::Article::Sender.lookup( :id => record.sender_id )
  12. type = Ticket::Article::Type.lookup( :id => record.type_id )
  13. if sender.name != 'Agent' && type.name !~ /^phone/
  14. return true
  15. end
  16. # if article is a message to customer
  17. return true if !type.communication
  18. # check if first_response is already set
  19. return true if record.ticket.first_response
  20. # set first_response
  21. record.ticket.first_response = record.created_at
  22. # save ticket
  23. record.ticket.save
  24. end
  25. end