[#6636] Add Deliverable#spent_for_user to get the billable/non-billable cost by user

This commit is contained in:
Eric Davis
2011-10-13 11:07:31 -07:00
parent 19ec0f6c43
commit f972efffbf
2 changed files with 45 additions and 0 deletions

View File

@@ -337,6 +337,12 @@ class Deliverable < ActiveRecord::Base
end
end
def 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(&:cost)
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])

View File

@@ -279,4 +279,43 @@ class DeliverableTest < ActiveSupport::TestCase
end
end
context "#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,
:amount => 100
})
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @billable_activity,
:user => @manager,
:hours => 5,
:amount => 100
})
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @non_billable_activity,
:user => @manager,
:hours => 5,
:amount => 100
})
end
context "with billable_time_only as true" do
should "return the total cost the user has logged on billable time entries" do
assert_equal 1000, @deliverable.spent_for_user(@manager, true)
end
end
context "with billable_time_only as false" do
should "return the total cost the user has logged on non-billable time entries" do
assert_equal 500, @deliverable.spent_for_user(@manager, false)
end
end
end
end