[#4420] Changed the approach for Retainer calculations by using an optional parameter.

This commit is contained in:
Eric Davis committed 2010-09-08 17:49:51 -07:00
1 parent c8b86db4c4
commit 82dec74eb7
6 files changed
+127 -70

No files matched your search

+12 -8
View File
@@ -54,20 +54,20 @@ class Deliverable < ActiveRecord::Base
end end
end end
def labor_budget_total def labor_budget_total(date=nil)
labor_budgets.sum(:budget) labor_budgets.sum(:budget)
end end
def labor_budget_total_for_date(date=nil) #Used on subclasses def overhead_budget_total(date=nil)
labor_budget_total
end
def overhead_budget_total
overhead_budgets.sum(:budget) overhead_budgets.sum(:budget)
end end
def overhead_budget_total_for_date(date=nil) #Used on subclasses def profit_budget(date=nil)
overhead_budget_total nil
end
def labor_budget_hours(date=nil)
labor_budgets.sum(:hours)
end end
# Total number of hours estimated in the Deliverable's budgets # Total number of hours estimated in the Deliverable's budgets
@@ -81,6 +81,10 @@ class Deliverable < ActiveRecord::Base
issues.inject(0) {|total, issue| total += issue.spent_hours } issues.inject(0) {|total, issue| total += issue.spent_hours }
end end
def filter_by_date(date=nil, &block)
block.call
end
def retainer? def retainer?
type == "RetainerDeliverable" type == "RetainerDeliverable"
end end
+4 -4
View File
@@ -11,7 +11,7 @@ class FixedDeliverable < Deliverable
'F' 'F'
end end
def total def total(date=nil)
read_attribute(:total) || 0.0 read_attribute(:total) || 0.0
end end
@@ -22,9 +22,9 @@ class FixedDeliverable < Deliverable
# The amount of profit that is budgeted for this deliverable. # The amount of profit that is budgeted for this deliverable.
# Profit = Total - ( Labor + Overhead + Fixed + Markup ) # Profit = Total - ( Labor + Overhead + Fixed + Markup )
def profit_budget def profit_budget(date=nil)
budgets = labor_budget_total + overhead_budget_total budgets = labor_budget_total(date) + overhead_budget_total(date)
(total || 0.0) - budgets (total(date) || 0.0) - budgets
end end
# The amount of money remaining after expenses have been taken out # The amount of money remaining after expenses have been taken out
+5 -5
View File
@@ -14,12 +14,12 @@ class HourlyDeliverable < Deliverable
'H' 'H'
end end
def total def total(date=nil)
return 0 if contract.nil? return 0 if contract.nil?
return 0 if contract.billable_rate.blank? return 0 if contract.billable_rate.blank?
return 0 if labor_budgets.count == 0 && overhead_budgets.count == 0 return 0 if labor_budgets.count == 0 && overhead_budgets.count == 0
return contract.billable_rate * labor_budgets.sum(:hours) return contract.billable_rate * labor_budget_hours(date)
end end
# Total amount to be billed on the deliverable, using the total time logged # Total amount to be billed on the deliverable, using the total time logged
@@ -49,9 +49,9 @@ class HourlyDeliverable < Deliverable
# The amount of profit that is budgeted for this deliverable # The amount of profit that is budgeted for this deliverable
# Profit = Total - ( Labor + Overhead + Fixed + Markup ) # Profit = Total - ( Labor + Overhead + Fixed + Markup )
def profit_budget def profit_budget(date=nil)
budgets = labor_budget_total + overhead_budget_total budgets = labor_budget_total(date) + overhead_budget_total(date)
(total || 0.0) - budgets (total(date) || 0.0) - budgets
end end
# The amount of money remaining after expenses have been taken out # The amount of money remaining after expenses have been taken out
+16 -4
View File
@@ -75,7 +75,7 @@ class RetainerDeliverable < HourlyDeliverable
budgets budgets
end end
def labor_budget_total_for_date(date=nil) def labor_budget_total(date=nil)
if date if date
if within_date_range?(date) if within_date_range?(date)
labor_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month}) labor_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
@@ -83,11 +83,11 @@ class RetainerDeliverable < HourlyDeliverable
0 # outside of range 0 # outside of range
end end
else else
labor_budgets.sum(:budget) super
end end
end end
def overhead_budget_total_for_date(date=nil) def overhead_budget_total(date=nil)
if date if date
if within_date_range?(date) if within_date_range?(date)
overhead_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month}) overhead_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
@@ -95,7 +95,19 @@ class RetainerDeliverable < HourlyDeliverable
0 # outside of range 0 # outside of range
end end
else else
overhead_budgets.sum(:budget) super
end
end
def labor_budget_hours(date=nil)
if date
if within_date_range?(date)
labor_budgets.sum(:hours, :conditions => {:year => date.year, :month => date.month})
else
0 # outside of range
end
else
super
end end
end end
-33
View File
@@ -34,37 +34,4 @@ class DeliverableTest < ActiveSupport::TestCase
end end
end end
context "#labor_budget_spent_for_period" do
should "use all periods"
end
context "#labor_budget_total_for_period" do
should "use all periods"
end
context "#overhead_spent_for_period" do
should "use all periods"
end
context "#overhead_budget_total_for_period" do
should "use all periods"
end
context "#profit_left_for_period" do
should "use all periods"
end
context "#profit_budget_for_period" do
should "use all periods"
end
context "#total_spent_for_period" do
should "use all periods"
end
context "#total_for_period" do
should "use all periods"
end
end end
+90 -16
View File
@@ -80,7 +80,7 @@ class RetainerDeliverableTest < ActiveSupport::TestCase
end end
end end
context "#labor_budget_spent_for_date" do context "#labor_budget_spent" do
context "with a empty period" do context "with a empty period" do
should "use all periods" should "use all periods"
end end
@@ -94,7 +94,7 @@ class RetainerDeliverableTest < ActiveSupport::TestCase
end end
end end
context "#labor_budget_total_for_date" do context "#labor_budget_total" do
setup do setup do
@deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31') @deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31')
@deliverable.labor_budgets << LaborBudget.spawn(:budget => 100, :hours => 10) @deliverable.labor_budgets << LaborBudget.spawn(:budget => 100, :hours => 10)
@@ -103,32 +103,32 @@ class RetainerDeliverableTest < ActiveSupport::TestCase
context "with a empty period" do context "with a empty period" do
should "use all periods" do should "use all periods" do
assert_equal 300.0, @deliverable.labor_budget_total_for_date(nil) assert_equal 300.0, @deliverable.labor_budget_total(nil)
end end
end end
context "with a period out of the retainer range" do context "with a period out of the retainer range" do
should "filter the records" do should "filter the records" do
assert_equal 0, @deliverable.labor_budget_total_for_date(Date.new(2011,1,1)) assert_equal 0, @deliverable.labor_budget_total(Date.new(2011,1,1))
end end
end end
context "with an invalid period" do context "with an invalid period" do
should "return 0" do should "return 0" do
assert_equal 0, @deliverable.labor_budget_total_for_date('1') assert_equal 0, @deliverable.labor_budget_total('1')
end end
end end
context "with a period in the retainer range" do context "with a period in the retainer range" do
should "filter the records" do should "filter the records" do
assert_equal 100.0, @deliverable.labor_budget_total_for_date(Date.new(2010,2,1)) assert_equal 100.0, @deliverable.labor_budget_total(Date.new(2010,2,1))
end end
end end
end end
# context "#overhead_spent_for_date" # context "#overhead_spent"
context "#overhead_budget_total_for_date" do context "#overhead_budget_total" do
setup do setup do
@deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31') @deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31')
@deliverable.overhead_budgets << OverheadBudget.spawn(:budget => 100, :hours => 10) @deliverable.overhead_budgets << OverheadBudget.spawn(:budget => 100, :hours => 10)
@@ -137,31 +137,105 @@ class RetainerDeliverableTest < ActiveSupport::TestCase
context "with a empty period" do context "with a empty period" do
should "use all periods" do should "use all periods" do
assert_equal 300.0, @deliverable.overhead_budget_total_for_date(nil) assert_equal 300.0, @deliverable.overhead_budget_total(nil)
end end
end end
context "with a period out of the retainer range" do context "with a period out of the retainer range" do
should "filter the records" do should "filter the records" do
assert_equal 0, @deliverable.overhead_budget_total_for_date(Date.new(2011,1,1)) assert_equal 0, @deliverable.overhead_budget_total(Date.new(2011,1,1))
end end
end end
context "with an invalid period" do context "with an invalid period" do
should "return 0" do should "return 0" do
assert_equal 0, @deliverable.overhead_budget_total_for_date('1') assert_equal 0, @deliverable.overhead_budget_total('1')
end end
end end
context "with a period in the retainer range" do context "with a period in the retainer range" do
should "filter the records" do should "filter the records" do
assert_equal 100.0, @deliverable.overhead_budget_total_for_date(Date.new(2010,2,1)) assert_equal 100.0, @deliverable.overhead_budget_total(Date.new(2010,2,1))
end end
end end
end end
# context "#profit_left_for_date" # context "#profit_left"
# context "#profit_budget_for_date"
# context "#total_spent_for_date" context "#profit_budget" do
# context "#total_for_date" setup do
@contract = Contract.generate!(:billable_rate => 100)
@deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31', :contract => @contract)
@deliverable.labor_budgets << LaborBudget.spawn(:budget => 100, :hours => 10)
@deliverable.overhead_budgets << OverheadBudget.spawn(:budget => 100, :hours => 10)
@deliverable.save!
assert_equal 100 * 30, @deliverable.total
assert_equal 2400, @deliverable.profit_budget # 3000 - 300 - 300
end
context "with a empty period" do
should "use all periods" do
assert_equal 2400, @deliverable.profit_budget(nil)
end
end
context "with a period out of the retainer range" do
should "filter the records" do
assert_equal 0, @deliverable.profit_budget(Date.new(2011,1,1))
end
end
context "with an invalid period" do
should "return 0" do
assert_equal 0, @deliverable.profit_budget('1')
end
end
context "with a period in the retainer range" do
should "filter the records" do
assert_equal 1000 - 200, @deliverable.profit_budget(Date.new(2010,2,1))
end
end
end
# context "#total_spent"
context "#total" do
setup do
@contract = Contract.generate!(:billable_rate => 100)
@deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31', :contract => @contract)
@deliverable.labor_budgets << LaborBudget.spawn(:budget => 100, :hours => 10)
@deliverable.overhead_budgets << OverheadBudget.spawn(:budget => 100, :hours => 10)
@deliverable.save!
assert_equal 100 * 30, @deliverable.total
end
context "with a empty period" do
should "use all periods" do
assert_equal 3000, @deliverable.total(nil)
end
end
context "with a period out of the retainer range" do
should "filter the records" do
assert_equal 0, @deliverable.total(Date.new(2011,1,1))
end
end
context "with an invalid period" do
should "return 0" do
assert_equal 0, @deliverable.total('1')
end
end
context "with a period in the retainer range" do
should "filter the records" do
assert_equal 1000, @deliverable.total(Date.new(2010,2,1))
end
end
end
end end