Fixed first response detection.

This commit is contained in:
Martin Edenhofer 2015-09-23 01:50:38 +02:00
parent 9d6b313601
commit e3277a3b8a
2 changed files with 30 additions and 7 deletions

View file

@ -32,9 +32,9 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
return true if record.internal
# if sender is not agent
sender = Ticket::Article::Sender.lookup( id: record.sender_id )
type = Ticket::Article::Type.lookup( id: record.type_id )
return true if sender.name != 'Agent' && type.name !~ /^phone/
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
type = Ticket::Article::Type.lookup(id: record.type_id)
return true if sender.name != 'Agent'
# if article is a message to customer
return true if !type.communication
@ -52,7 +52,7 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
def sender_type_update(record)
# ignore if create channel is already set
count = Ticket::Article.where( ticket_id: record.ticket_id ).count
count = Ticket::Article.where(ticket_id: record.ticket_id).count
return if count > 1
record.ticket.create_article_type_id = record.type_id
@ -66,10 +66,10 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
return true if record.internal
# if article is a message to customer
return true if !Ticket::Article::Type.lookup( id: record.type_id ).communication
return true if !Ticket::Article::Type.lookup(id: record.type_id).communication
# if sender is customer
sender = Ticket::Article::Sender.lookup( id: record.sender_id )
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
if sender.name == 'Customer'
# check if last communication is done by agent, else do not set last_contact_customer

View file

@ -394,7 +394,30 @@ class TicketSlaTest < ActiveSupport::TestCase
assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - inbound' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' )
assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound' )
assert_equal( ticket.first_response.to_s, article_inbound.created_at.to_s, 'ticket.first_response verify - inbound' )
assert_equal( ticket.first_response, nil, 'ticket.first_response verify - inbound' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
# create outbound article
article_outbound = Ticket::Article.create(
ticket_id: ticket.id,
from: 'some_sender@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message',
internal: false,
sender: Ticket::Article::Sender.where(name: 'Agent').first,
type: Ticket::Article::Type.where(name: 'phone').first,
updated_by_id: 1,
created_by_id: 1,
created_at: '2013-03-28 23:55:00 UTC',
updated_at: '2013-03-28 23:55:00 UTC',
)
ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 2, 'ticket.article_count verify - inbound' )
assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - inbound' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' )
assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - inbound' )
assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - inbound' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
delete = sla.destroy