[#2844] Added an API to get the total number of billable and overhead hours.
* Added Issue#billable_time_spent * Added Issue#overhead_time_spent * Added specs
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
require_dependency 'issue'
|
||||
|
||||
module OverheadIssuePatch
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def billable_time_spent
|
||||
time_entry_hours_based_on_billable_flag(true)
|
||||
end
|
||||
|
||||
def overhead_time_spent
|
||||
time_entry_hours_based_on_billable_flag(false)
|
||||
end
|
||||
|
||||
private
|
||||
# Totals time_entries that are billable (true) or overhead (false)
|
||||
# and returns the rounded value
|
||||
def time_entry_hours_based_on_billable_flag(billable_flag=true)
|
||||
time = time_entries.inject(0.0) {|sum, time_entry|
|
||||
sum += time_entry.hours if time_entry.billable? == billable_flag
|
||||
sum
|
||||
}
|
||||
if time > 0
|
||||
return time.round(1)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user