time_accounting.rb 672 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Ticket::TimeAccounting < ApplicationModel
  3. belongs_to :ticket, optional: true
  4. belongs_to :ticket_article, class_name: 'Ticket::Article', inverse_of: :ticket_time_accounting, optional: true
  5. after_create :update_time_units
  6. after_update :update_time_units
  7. def update_time_units
  8. self.class.update_ticket(ticket)
  9. end
  10. def self.update_ticket(ticket)
  11. time_units = total(ticket)
  12. return if ticket.time_unit.to_d == time_units
  13. ticket.time_unit = time_units
  14. ticket.save!
  15. end
  16. def self.total(ticket)
  17. ticket.ticket_time_accounting.sum(:time_unit)
  18. end
  19. end