Permalink
Browse files

Add billable/non_billable methods to Project (from redmine_contracts)

  • Loading branch information...
1 parent d574e52 commit 7bfe9932e45c01718a0afb72cb61a8cbbf468184 @edavis10 committed Nov 15, 2011
Showing with 43 additions and 0 deletions.
  1. +2 −0 init.rb
  2. +41 −0 lib/redmine_overhead/patches/project_patch.rb
View
@@ -23,6 +23,8 @@
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'
@@ -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

0 comments on commit 7bfe993

Please sign in to comment.