From 7bfe9932e45c01718a0afb72cb61a8cbbf468184 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 14 Nov 2011 16:28:45 -0800 Subject: [PATCH] Add billable/non_billable methods to Project (from redmine_contracts) --- init.rb | 2 + lib/redmine_overhead/patches/project_patch.rb | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/redmine_overhead/patches/project_patch.rb 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