[#4183] Implemented Contract#total_budget.

This commit is contained in:
Eric Davis
2010-07-07 16:01:47 -07:00
parent 91b16a2310
commit f89e0bf14a
2 changed files with 19 additions and 1 deletions
+7 -1
View File
@@ -30,7 +30,7 @@ class Contract < ActiveRecord::Base
attr_accessible :details
[:status, :contract_type, :labor_spent, :overhead_spent,
:fixed_spent, :fixed_budget, :total_spent, :total_budget,
:fixed_spent, :fixed_budget, :total_spent,
:markup_spent, :markup_budget, :profit_spent, :profit_budget,
:discount_spent, :discount_budget, :client_point_of_contact,
:estimated_hour_spent
@@ -48,10 +48,16 @@ class Contract < ActiveRecord::Base
deliverables.inject(0) {|total, deliverable| total += deliverable.overhead_budget_total }
end
# OPTIMIZE: N+1
def estimated_hour_budget
deliverables.inject(0) {|total, deliverable| total += deliverable.estimated_hour_budget_total }
end
# OPTIMIZE: N+1
def total_budget
deliverables.inject(0) {|total, deliverable| total += deliverable.total }
end
PaymentTerms = {
:net_0 => :text_payment_terms_net_0,
:net_15 => :text_payment_terms_net_15,
+12
View File
@@ -68,4 +68,16 @@ class ContractTest < ActiveSupport::TestCase
assert_equal 110, contract.estimated_hour_budget
end
end
context "#total_budget" do
should "sum all of the totals of the Deliverables" do
contract = Contract.generate!(:billable_rate => 100.0)
contract.deliverables << @deliverable_1 = FixedDeliverable.generate!(:total => 10_000)
contract.deliverables << @deliverable_2 = HourlyDeliverable.generate!
LaborBudget.generate!(:deliverable => @deliverable_2, :hours => 10)
OverheadBudget.generate!(:deliverable => @deliverable_2, :hours => 20)
assert_equal 10_000 + (30 * 100), contract.total_budget
end
end
end