You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time_entry_activity.rb 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class TimeEntryActivity < Enumeration
  19. has_many :time_entries, :foreign_key => 'activity_id'
  20. OptionName = :enumeration_activities
  21. def self.default(project=nil)
  22. default_activity = super()
  23. if default_activity.nil? || project.nil? || project.activities.blank? || project.activities.include?(default_activity)
  24. return default_activity
  25. end
  26. project.activities.detect { |activity| activity.parent_id == default_activity.id }
  27. end
  28. def option_name
  29. OptionName
  30. end
  31. def objects
  32. TimeEntry.where(:activity_id => self_and_descendants(1).map(&:id))
  33. end
  34. def objects_count
  35. objects.count
  36. end
  37. def transfer_relations(to)
  38. objects.update_all(:activity_id => to.id)
  39. end
  40. end