trabajo-afectivo/app/models/ticket/time_accounting.rb

27 lines
672 B
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# 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
2017-04-07 14:44:34 +00:00
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