From 26aac777e418bdb65d7724a0593ca0b2c38791d1 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 7 Jul 2010 15:25:21 -0700 Subject: [PATCH] [#4183] Implemented Contract#estimated_hour_budget --- app/models/contract.rb | 6 +++++- app/models/deliverable.rb | 6 ++++++ test/unit/contract_test.rb | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/models/contract.rb b/app/models/contract.rb index 8c6a284..9407b02 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -33,7 +33,7 @@ class Contract < ActiveRecord::Base :fixed_spent, :fixed_budget, :total_spent, :total_budget, :markup_spent, :markup_budget, :profit_spent, :profit_budget, :discount_spent, :discount_budget, :client_point_of_contact, - :estimated_hour_spent, :estimated_hour_budget + :estimated_hour_spent ].each do |mthd| define_method(mthd) { "TODO" } end @@ -48,6 +48,10 @@ class Contract < ActiveRecord::Base deliverables.inject(0) {|total, deliverable| total += deliverable.overhead_budget_total } end + def estimated_hour_budget + deliverables.inject(0) {|total, deliverable| total += deliverable.estimated_hour_budget_total } + end + PaymentTerms = { :net_0 => :text_payment_terms_net_0, :net_15 => :text_payment_terms_net_15, diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index 8e169ff..72cc848 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -42,6 +42,12 @@ class Deliverable < ActiveRecord::Base overhead_budgets.sum(:budget) end + # Total number of hours estimated in the Deliverable's budgets + def estimated_hour_budget_total + (labor_budgets.sum(:hours) || 0.0) + + (overhead_budgets.sum(:hours) || 0.0) + end + if Rails.env.test? generator_for :title, :method => :next_title diff --git a/test/unit/contract_test.rb b/test/unit/contract_test.rb index 97dd511..535cd40 100644 --- a/test/unit/contract_test.rb +++ b/test/unit/contract_test.rb @@ -56,4 +56,16 @@ class ContractTest < ActiveSupport::TestCase assert_equal 200, contract.overhead_budget end end + + context "#estimated_hour_budget" do + should "sum all of the labor and overhead budgets of the Deliverables" do + contract = Contract.generate! + contract.deliverables << @deliverable_1 = FixedDeliverable.generate! + LaborBudget.generate!(:deliverable => @deliverable_1, :hours => 50) + contract.deliverables << @deliverable_2 = HourlyDeliverable.generate! + OverheadBudget.generate!(:deliverable => @deliverable_2, :hours => 60) + + assert_equal 110, contract.estimated_hour_budget + end + end end