trabajo-afectivo/app/models/ticket/time_accounting.rb
2022-01-01 14:38:12 +01:00

26 lines
672 B
Ruby

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class Ticket::TimeAccounting < ApplicationModel
belongs_to :ticket, optional: true
belongs_to :ticket_article, class_name: 'Ticket::Article', inverse_of: :ticket_time_accounting, optional: true
after_create :update_time_units
after_update :update_time_units
def update_time_units
self.class.update_ticket(ticket)
end
def self.update_ticket(ticket)
time_units = total(ticket)
return if ticket.time_unit.to_d == time_units
ticket.time_unit = time_units
ticket.save!
end
def self.total(ticket)
ticket.ticket_time_accounting.sum(:time_unit)
end
end