2017-01-16 13:34:44 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
class Ticket::TimeAccounting < ApplicationModel
|
|
|
|
|
2019-07-04 11:16:55 +00:00
|
|
|
belongs_to :ticket, optional: true
|
|
|
|
belongs_to :ticket_article, class_name: 'Ticket::Article', inverse_of: :ticket_time_accounting, optional: true
|
2017-04-07 14:44:34 +00:00
|
|
|
|
2017-01-16 13:34:44 +00:00
|
|
|
after_create :ticket_time_unit_update
|
|
|
|
after_update :ticket_time_unit_update
|
|
|
|
|
|
|
|
def ticket_time_unit_update
|
|
|
|
exists = false
|
|
|
|
time_units = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
Ticket::TimeAccounting.where(ticket_id: ticket_id).each do |record|
|
2017-01-16 13:34:44 +00:00
|
|
|
time_units += record.time_unit
|
|
|
|
exists = true
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-01-16 13:34:44 +00:00
|
|
|
return false if exists == false
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-16 13:34:44 +00:00
|
|
|
ticket = Ticket.lookup(id: ticket_id)
|
|
|
|
return false if !ticket
|
|
|
|
return false if ticket.time_unit == time_units
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-16 13:34:44 +00:00
|
|
|
ticket.time_unit = time_units
|
|
|
|
ticket.save!
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|