[#4183] Implemented Contract#estimated_hour_spent and Deliverable#hours_spent_total.
This commit is contained in:
@@ -41,8 +41,7 @@ class Contract < ActiveRecord::Base
|
||||
[:labor_spent,
|
||||
:overhead_spent,
|
||||
:total_spent,
|
||||
:profit_spent,
|
||||
:estimated_hour_spent
|
||||
:profit_spent
|
||||
].each do |mthd|
|
||||
define_method(mthd) { "TODO" }
|
||||
end
|
||||
@@ -62,6 +61,11 @@ class Contract < ActiveRecord::Base
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.estimated_hour_budget_total }
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def estimated_hour_spent
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.hours_spent_total }
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def total_budget
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.total }
|
||||
|
||||
@@ -48,6 +48,11 @@ class Deliverable < ActiveRecord::Base
|
||||
(overhead_budgets.sum(:hours) || 0.0)
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def hours_spent_total
|
||||
issues.inject(0) {|total, issue| total += issue.spent_hours }
|
||||
end
|
||||
|
||||
if Rails.env.test?
|
||||
generator_for :title, :method => :next_title
|
||||
|
||||
|
||||
@@ -69,6 +69,26 @@ class ContractTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "#estimated_hour_spent" do
|
||||
should "sum all of the hours spent on the Deliverables" do
|
||||
@project = Project.generate!
|
||||
contract = Contract.generate!
|
||||
contract.deliverables << @deliverable_1 = FixedDeliverable.generate!
|
||||
@deliverable_1.issues << @issue1 = Issue.generate_for_project!(@project)
|
||||
@deliverable_1.issues << @issue2 = Issue.generate_for_project!(@project)
|
||||
TimeEntry.generate!(:hours => 10, :issue => @issue1, :project => @project)
|
||||
TimeEntry.generate!(:hours => 10, :issue => @issue2, :project => @project)
|
||||
|
||||
contract.deliverables << @deliverable_2 = HourlyDeliverable.generate!
|
||||
@deliverable_2.issues << @issue3 = Issue.generate_for_project!(@project)
|
||||
@deliverable_2.issues << @issue4 = Issue.generate_for_project!(@project)
|
||||
TimeEntry.generate!(:hours => 10, :issue => @issue3, :project => @project)
|
||||
TimeEntry.generate!(:hours => 10, :issue => @issue4, :project => @project)
|
||||
|
||||
assert_equal 40, contract.estimated_hour_spent
|
||||
end
|
||||
end
|
||||
|
||||
context "#total_budget" do
|
||||
should "sum all of the totals of the Deliverables" do
|
||||
contract = Contract.generate!(:billable_rate => 100.0)
|
||||
|
||||
Reference in New Issue
Block a user