2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-01-16 13:34:44 +00:00
|
|
|
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
|
|
|
|
2020-10-23 11:53:34 +00:00
|
|
|
after_create :update_time_units
|
|
|
|
after_update :update_time_units
|
2017-01-16 13:34:44 +00:00
|
|
|
|
2020-10-23 11:53:34 +00:00
|
|
|
def update_time_units
|
|
|
|
self.class.update_ticket(ticket)
|
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2020-10-23 11:53:34 +00:00
|
|
|
def self.update_ticket(ticket)
|
|
|
|
time_units = total(ticket)
|
|
|
|
return if ticket.time_unit.to_d == 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!
|
|
|
|
end
|
|
|
|
|
2020-10-23 11:53:34 +00:00
|
|
|
def self.total(ticket)
|
|
|
|
ticket.ticket_time_accounting.sum(:time_unit)
|
|
|
|
end
|
2017-01-16 13:34:44 +00:00
|
|
|
end
|