Removed all the duplicate methods that were getting the rate for each TimeEntry
and replaced them with a simple collector that uses the new TimeEntry#cost method (that wraps the Rate API). #1924
This commit is contained in:
1 parent
7fa4f33748
commit
3d8c1ecc5c
6 files changed
+9
-42
No files matched your search
+3
-16
@@ -110,15 +110,8 @@ class Budget
|
|||||||
# Dollar amount of time that has been logged to the project itself
|
# Dollar amount of time that has been logged to the project itself
|
||||||
def amount_missing_on_issues
|
def amount_missing_on_issues
|
||||||
time_logs = TimeEntry.find_all_by_project_id_and_issue_id(self.project, nil)
|
time_logs = TimeEntry.find_all_by_project_id_and_issue_id(self.project, nil)
|
||||||
total = 0
|
|
||||||
|
return time_logs.collect(&:cost).inject { |sum, n| sum + n}
|
||||||
# Find each Member for their rate
|
|
||||||
time_logs.each do |time_log|
|
|
||||||
rate = Rate.amount_for(time_log.user, time_log.project, time_log.spent_on.to_s)
|
|
||||||
total += (rate * time_log.hours) unless rate.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
return total
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dollar amount of time that has been logged to issues that are not assigned to deliverables
|
# Dollar amount of time that has been logged to issues that are not assigned to deliverables
|
||||||
@@ -132,14 +125,8 @@ class Budget
|
|||||||
return 0 if all_issues.empty?
|
return 0 if all_issues.empty?
|
||||||
missing_issues = all_issues - deliverable_issues
|
missing_issues = all_issues - deliverable_issues
|
||||||
|
|
||||||
|
|
||||||
time_logs = missing_issues.collect(&:time_entries).flatten
|
time_logs = missing_issues.collect(&:time_entries).flatten
|
||||||
|
|
||||||
time_logs.each do |time_log|
|
return time_logs.collect(&:cost).inject { |sum, n| sum + n}
|
||||||
rate = Rate.amount_for(time_log.user, time_log.project, time_log.spent_on.to_s)
|
|
||||||
total += (rate * time_log.hours) unless rate.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
return total
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -16,14 +16,8 @@ class FixedDeliverable < Deliverable
|
|||||||
|
|
||||||
# Get all timelogs assigned
|
# Get all timelogs assigned
|
||||||
time_logs = self.issues.collect(&:time_entries).flatten
|
time_logs = self.issues.collect(&:time_entries).flatten
|
||||||
|
|
||||||
# Find each Member for their rate
|
|
||||||
time_logs.each do |time_log|
|
|
||||||
rate = Rate.amount_for(time_log.user, time_log.project, time_log.spent_on.to_s)
|
|
||||||
total += (rate * time_log.hours) unless rate.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
return total
|
return total + time_logs.collect(&:cost).inject { |sum, n| sum + n}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,7 @@ class HourlyDeliverable < Deliverable
|
|||||||
# Get all timelogs assigned
|
# Get all timelogs assigned
|
||||||
time_logs = self.issues.collect(&:time_entries).flatten
|
time_logs = self.issues.collect(&:time_entries).flatten
|
||||||
|
|
||||||
# Find each Member for their rate
|
return time_logs.collect(&:cost).inject { |sum, n| sum + n}
|
||||||
time_logs.each do |time_log|
|
|
||||||
rate = Rate.amount_for(time_log.user, time_log.project, time_log.spent_on.to_s)
|
|
||||||
total += (rate * time_log.hours) unless rate.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
return total
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def profit # :nodoc:
|
def profit # :nodoc:
|
||||||
|
|||||||
@@ -25,15 +25,9 @@ class MemberSpent
|
|||||||
project.members.each do |member|
|
project.members.each do |member|
|
||||||
member_time_entries = time_entries.select { |tl| tl.user_id == member.user.id}
|
member_time_entries = time_entries.select { |tl| tl.user_id == member.user.id}
|
||||||
|
|
||||||
spent = 0.0
|
spent = member_time_entries.collect(&:cost).inject { |sum, n| sum + n}
|
||||||
hours = 0.0
|
hours = member_time_entries.collect(&:hours).inject { |sum, n| sum + n}
|
||||||
|
|
||||||
member_time_entries.each do |time_entry|
|
|
||||||
rate = Rate.amount_for(time_entry.user, time_entry.project, time_entry.spent_on.to_s)
|
|
||||||
spent += time_entry.hours.to_f * rate unless rate.nil?
|
|
||||||
hours += time_entry.hours
|
|
||||||
end
|
|
||||||
|
|
||||||
membership << MemberSpent.new({
|
membership << MemberSpent.new({
|
||||||
:user => member.user,
|
:user => member.user,
|
||||||
:hours => hours,
|
:hours => hours,
|
||||||
|
|||||||
@@ -26,10 +26,9 @@ describe FixedDeliverable, '.spent' do
|
|||||||
@issue1 = mock_model(Issue)
|
@issue1 = mock_model(Issue)
|
||||||
|
|
||||||
@issue_1_time_entry = mock_model(TimeEntry, :issue_id => @issue1.id, :user => @user, :project => @project, :hours => 1.0, :spent_on => Date.today)
|
@issue_1_time_entry = mock_model(TimeEntry, :issue_id => @issue1.id, :user => @user, :project => @project, :hours => 1.0, :spent_on => Date.today)
|
||||||
|
@issue_1_time_entry.should_receive(:cost).and_return(60.0)
|
||||||
@issue1.stub!(:time_entries).and_return([@issue_1_time_entry])
|
@issue1.stub!(:time_entries).and_return([@issue_1_time_entry])
|
||||||
|
|
||||||
Rate.should_receive(:amount_for).with(@user, @project, @issue_1_time_entry.spent_on.to_s).and_return(60.0)
|
|
||||||
|
|
||||||
@deliverable = FixedDeliverable.new({ :subject => 'test' })
|
@deliverable = FixedDeliverable.new({ :subject => 'test' })
|
||||||
@issues = [@issue1]
|
@issues = [@issue1]
|
||||||
@deliverable.stub!(:fixed_cost).and_return(5000.0)
|
@deliverable.stub!(:fixed_cost).and_return(5000.0)
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ describe HourlyDeliverable, '.spent' do
|
|||||||
@issue1 = mock_model(Issue)
|
@issue1 = mock_model(Issue)
|
||||||
|
|
||||||
@issue_1_time_entry = mock_model(TimeEntry, :issue_id => @issue1.id, :user => @user, :project => @project, :hours => 1.0, :spent_on => Date.today)
|
@issue_1_time_entry = mock_model(TimeEntry, :issue_id => @issue1.id, :user => @user, :project => @project, :hours => 1.0, :spent_on => Date.today)
|
||||||
|
@issue_1_time_entry.should_receive(:cost).and_return(60.0)
|
||||||
@issue1.stub!(:time_entries).and_return([@issue_1_time_entry])
|
@issue1.stub!(:time_entries).and_return([@issue_1_time_entry])
|
||||||
|
|
||||||
Rate.should_receive(:amount_for).with(@user, @project, @issue_1_time_entry.spent_on.to_s).and_return(60.0)
|
|
||||||
|
|
||||||
@deliverable = HourlyDeliverable.new({ :subject => 'test' })
|
@deliverable = HourlyDeliverable.new({ :subject => 'test' })
|
||||||
@issues = [@issue1]
|
@issues = [@issue1]
|
||||||
@deliverable.should_receive(:issues).twice.and_return(@issues)
|
@deliverable.should_receive(:issues).twice.and_return(@issues)
|
||||||
|
|||||||
Reference in new issue
Block a user