[#6636] Add Deliverable#hours_spent_for_user to get the billable/non-billable hours by user

This commit is contained in:
Eric Davis
2011-10-13 11:02:23 -07:00
parent 2d39a4063a
commit 19ec0f6c43
2 changed files with 41 additions and 0 deletions

View File

@@ -337,6 +337,12 @@ class Deliverable < ActiveRecord::Base
end
end
def hours_spent_for_user(user, billable_time_only)
time_entries = project.time_entries.all(:conditions => ["#{TimeEntry.table_name}.issue_id IN (?) AND #{TimeEntry.table_name}.user_id IN (?)", issue_ids, user.id])
time_entries.select {|time| time.billable? == billable_time_only }.sum(&:hours)
end
def self.valid_types
['FixedDeliverable','HourlyDeliverable','RetainerDeliverable']
end

View File

@@ -244,4 +244,39 @@ class DeliverableTest < ActiveSupport::TestCase
end
end
context "#hours_spent_for_user" do
setup do
configure_overhead_plugin
create_contract_and_deliverable
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @billable_activity,
:user => @manager,
:hours => 5
})
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @billable_activity,
:user => @manager,
:hours => 5
})
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @non_billable_activity,
:user => @manager,
:hours => 5
})
end
context "with billable_time_only as true" do
should "return the total number of hours the user has logged on billable time entries" do
assert_equal 10, @deliverable.hours_spent_for_user(@manager, true)
end
end
context "with billable_time_only as false" do
should "return the total number of hours the user has logged on non-billable time entries" do
assert_equal 5, @deliverable.hours_spent_for_user(@manager, false)
end
end
end
end