diff --git a/init.rb b/init.rb index f689b4e..337cf0f 100644 --- a/init.rb +++ b/init.rb @@ -23,6 +23,8 @@ Dispatcher.to_prepare do require_dependency 'enumeration' require_dependency 'time_entry_activity' TimeEntryActivity.send(:include, OverheadTimeEntryActivityPatch) + require_dependency 'project' + Project.send(:include, RedmineOverhead::Patches::ProjectPatch) end require 'overhead_budget_hook' diff --git a/lib/redmine_overhead/patches/project_patch.rb b/lib/redmine_overhead/patches/project_patch.rb new file mode 100644 index 0000000..66941c7 --- /dev/null +++ b/lib/redmine_overhead/patches/project_patch.rb @@ -0,0 +1,41 @@ +module RedmineOverhead + module Patches + module ProjectPatch + def self.included(base) + base.extend(ClassMethods) + + base.send(:include, InstanceMethods) + base.class_eval do + unloadable + end + end + + module ClassMethods + end + + module InstanceMethods + def billable_activities + activities_sorted_by_billable[:billable] + end + + def non_billable_activities + activities_sorted_by_billable[:non_billable] + end + + private + + def activities_sorted_by_billable + split_activities = activities.partition do |activity| + activity.billable? + end + + { + :billable => split_activities.first, + :non_billable => split_activities.second + } + + end + end + end + end +end