[#6636] Add methods to Deliverable to find users with billable/non-billable time

This commit is contained in:
Eric Davis
2011-10-13 10:51:39 -07:00
parent bfe35fb1c8
commit 2d39a4063a
2 changed files with 82 additions and 0 deletions

View File

@@ -313,6 +313,30 @@ class Deliverable < ActiveRecord::Base
labor.to_f + overhead.to_f
end
# Array of users who have logged billable time to the deliverable
def users_with_billable_time
users_with_time(true)
end
# Array of users who have logged non-billable time to the deliverable
def users_with_non_billable_time
users_with_time(false)
end
# Array of users who have logged a type of time to the deliverable
#
# @params billable_time_only Boolean Only count billable (true) or non-billable (false) time
def users_with_time(billable_time_only)
time_entries = project.time_entries.all(:conditions => ["#{TimeEntry.table_name}.issue_id IN (?)", issue_ids])
time_entries.inject([]) do |users, time_entry|
if time_entry.billable? == billable_time_only
users << time_entry.user unless users.include?(time_entry.user)
end
users
end
end
def self.valid_types
['FixedDeliverable','HourlyDeliverable','RetainerDeliverable']
end

View File

@@ -186,4 +186,62 @@ class DeliverableTest < ActiveSupport::TestCase
end
context "#users_with_billable_time" do
setup do
configure_overhead_plugin
create_contract_and_deliverable
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @billable_activity,
:user => @manager
})
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @non_billable_activity,
:user => @manager
})
@non_billable_user = User.generate!
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @non_billable_activity,
:user => @non_billable_user
})
end
should "include users with billable Time Entries" do
assert @deliverable.users_with_billable_time.include?(@manager), "Manager not included"
end
should "not include users with only nonbillable Time Entries" do
assert !@deliverable.users_with_billable_time.include?(@non_billable_user), "Non billable user included"
end
end
context "#users_with_non_billable_time" do
setup do
configure_overhead_plugin
create_contract_and_deliverable
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @billable_activity,
:user => @manager
})
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @non_billable_activity,
:user => @manager
})
@billable_user = User.generate!
create_issue_with_time_for_deliverable(@deliverable, {
:activity => @billable_activity,
:user => @billable_user
})
end
should "include users with billable Time Entries" do
assert @deliverable.users_with_non_billable_time.include?(@manager), "Manager not included"
end
should "not include users with only nonbillable Time Entries" do
assert !@deliverable.users_with_non_billable_time.include?(@billable_user), "Billable user included"
end
end
end