Improved reset of last_contact/last_contact_customer (only reset on first customer follow up - needed for update time escalation).

This commit is contained in:
Martin Edenhofer 2015-10-30 11:05:51 +01:00
parent 1fb3ac5133
commit 519033174d
2 changed files with 98 additions and 18 deletions

View file

@ -70,12 +70,18 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
# if sender is customer # if sender is customer
sender = Ticket::Article::Sender.lookup(id: record.sender_id) sender = Ticket::Article::Sender.lookup(id: record.sender_id)
ticket = record.ticket
if sender.name == 'Customer' if sender.name == 'Customer'
# if customer is sending agains, ignore update of last contact (usecase of update escalation)
return true if ticket.last_contact_customer &&
ticket.last_contact &&
ticket.last_contact_customer == ticket.last_contact
# check if last communication is done by agent, else do not set last_contact_customer # check if last communication is done by agent, else do not set last_contact_customer
if record.ticket.last_contact_customer.nil? || if ticket.last_contact_customer.nil? ||
record.ticket.last_contact_agent.nil? || ticket.last_contact_agent.nil? ||
record.ticket.last_contact_agent.to_i > record.ticket.last_contact_customer.to_i ticket.last_contact_agent.to_i > ticket.last_contact_customer.to_i
# set last_contact customer # set last_contact customer
record.ticket.last_contact_customer = record.created_at record.ticket.last_contact_customer = record.created_at

View file

@ -18,26 +18,51 @@ class TicketTest < ActiveSupport::TestCase
assert_equal( ticket.group.name, 'Users', 'ticket.group verify' ) assert_equal( ticket.group.name, 'Users', 'ticket.group verify' )
assert_equal( ticket.state.name, 'new', 'ticket.state verify' ) assert_equal( ticket.state.name, 'new', 'ticket.state verify' )
# create inbound article # create inbound article #1
article_inbound = Ticket::Article.create( article_inbound1 = Ticket::Article.create(
ticket_id: ticket.id, ticket_id: ticket.id,
from: 'some_sender@example.com', from: 'some_sender@example.com',
to: 'some_recipient@example.com', to: 'some_recipient@example.com',
subject: 'some subject', subject: 'some subject',
message_id: 'some@id', message_id: 'some@id',
body: 'some message article_inbound 😍😍😍', body: 'some message article_inbound1 😍😍😍',
internal: false, internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first, sender: Ticket::Article::Sender.where(name: 'Customer').first,
type: Ticket::Article::Type.where(name: 'email').first, type: Ticket::Article::Type.where(name: 'email').first,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
assert_equal( article_inbound.body, 'some message article_inbound 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound' ) assert_equal( article_inbound1.body, 'some message article_inbound1 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound' )
ticket = Ticket.find(ticket.id) ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 1, 'ticket.article_count verify - inbound' ) assert_equal( ticket.article_count, 1, 'ticket.article_count verify - inbound' )
assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - inbound' ) assert_equal( ticket.last_contact.to_s, article_inbound1.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_customer.to_s, article_inbound1.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, nil, 'ticket.first_response verify - inbound' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
# create inbound article #2
sleep 2
article_inbound2 = Ticket::Article.create(
ticket_id: ticket.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message article_inbound2 😍😍😍',
internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first,
type: Ticket::Article::Type.where(name: 'email').first,
updated_by_id: 1,
created_by_id: 1,
)
assert_equal( article_inbound2.body, 'some message article_inbound2 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound' )
ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 2, 'ticket.article_count verify - inbound' )
assert_equal( ticket.last_contact.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - inbound' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound1.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.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound' )
assert_equal( ticket.first_response, nil, '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' ) assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' )
@ -58,15 +83,15 @@ class TicketTest < ActiveSupport::TestCase
assert_equal( article_note.body, "some\n message", 'article_note.body verify - inbound' ) assert_equal( article_note.body, "some\n message", 'article_note.body verify - inbound' )
ticket = Ticket.find(ticket.id) ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 2, 'ticket.article_count verify - note' ) assert_equal( ticket.article_count, 3, 'ticket.article_count verify - note' )
assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - note' ) assert_equal( ticket.last_contact.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact verify - note' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - note' ) assert_equal( ticket.last_contact_customer.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer verify - note' )
assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - note' ) assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - note' )
assert_equal( ticket.first_response, nil, 'ticket.first_response verify - note' ) assert_equal( ticket.first_response, nil, 'ticket.first_response verify - note' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - note' ) assert_equal( ticket.close_time, nil, 'ticket.close_time verify - note' )
# create outbound article # create outbound article
sleep 10 sleep 2
article_outbound = Ticket::Article.create( article_outbound = Ticket::Article.create(
ticket_id: ticket.id, ticket_id: ticket.id,
from: 'some_recipient@example.com', from: 'some_recipient@example.com',
@ -82,9 +107,58 @@ class TicketTest < ActiveSupport::TestCase
) )
ticket = Ticket.find(ticket.id) ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 3, 'ticket.article_count verify - outbound' ) assert_equal( ticket.article_count, 4, 'ticket.article_count verify - outbound' )
assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - outbound' ) assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - outbound' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - outbound' ) assert_equal( ticket.last_contact_customer.to_s, article_inbound1.created_at.to_s, 'ticket.last_contact_customer verify - outbound' )
assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound' )
assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - outbound' )
# create inbound article #3
article_inbound3 = Ticket::Article.create(
ticket_id: ticket.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message article_inbound3 😍😍😍',
internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first,
type: Ticket::Article::Type.where(name: 'email').first,
updated_by_id: 1,
created_by_id: 1,
)
assert_equal( article_inbound3.body, 'some message article_inbound3 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound' )
ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 5, 'ticket.article_count verify - inbound' )
assert_equal( ticket.last_contact.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - inbound' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound3.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 - outbound' )
assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - outbound' )
# create inbound article #4
sleep 2
article_inbound4 = Ticket::Article.create(
ticket_id: ticket.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message article_inbound4 😍😍😍',
internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first,
type: Ticket::Article::Type.where(name: 'email').first,
updated_by_id: 1,
created_by_id: 1,
)
assert_equal( article_inbound4.body, 'some message article_inbound4 😍😍😍'.utf8_to_3bytesutf8, 'article_inbound.body verify - inbound' )
ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 6, 'ticket.article_count verify - inbound' )
assert_equal( ticket.last_contact.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - inbound' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound3.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 - outbound' ) assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - outbound' )
assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound' ) assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - outbound' )
assert_equal( ticket.close_time, nil, 'ticket.close_time verify - outbound' ) assert_equal( ticket.close_time, nil, 'ticket.close_time verify - outbound' )
@ -93,9 +167,9 @@ class TicketTest < ActiveSupport::TestCase
ticket.save ticket.save
ticket = Ticket.find(ticket.id) ticket = Ticket.find(ticket.id)
assert_equal( ticket.article_count, 3, 'ticket.article_count verify - state update' ) assert_equal( ticket.article_count, 6, 'ticket.article_count verify - state update' )
assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - state update' ) assert_equal( ticket.last_contact.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact verify - state update' )
assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - state update' ) assert_equal( ticket.last_contact_customer.to_s, article_inbound3.created_at.to_s, 'ticket.last_contact_customer verify - state update' )
assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - state update' ) assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - state update' )
assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - state update' ) assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - state update' )
assert( ticket.close_time, 'ticket.close_time verify - state update' ) assert( ticket.close_time, 'ticket.close_time verify - state update' )