[#4420] Added a second Retainer calculation method for specific dates.
This commit is contained in:
1 parent
0cc2523084
commit
c8b86db4c4
3 files changed
+49
-1
No files matched your search
@@ -66,6 +66,10 @@ class Deliverable < ActiveRecord::Base
|
|||||||
overhead_budgets.sum(:budget)
|
overhead_budgets.sum(:budget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def overhead_budget_total_for_date(date=nil) #Used on subclasses
|
||||||
|
overhead_budget_total
|
||||||
|
end
|
||||||
|
|
||||||
# Total number of hours estimated in the Deliverable's budgets
|
# Total number of hours estimated in the Deliverable's budgets
|
||||||
def estimated_hour_budget_total
|
def estimated_hour_budget_total
|
||||||
(labor_budgets.sum(:hours) || 0.0) +
|
(labor_budgets.sum(:hours) || 0.0) +
|
||||||
|
|||||||
@@ -87,6 +87,18 @@ class RetainerDeliverable < HourlyDeliverable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def overhead_budget_total_for_date(date=nil)
|
||||||
|
if date
|
||||||
|
if within_date_range?(date)
|
||||||
|
overhead_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
|
||||||
|
else
|
||||||
|
0 # outside of range
|
||||||
|
end
|
||||||
|
else
|
||||||
|
overhead_budgets.sum(:budget)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_budgets_for_periods
|
def create_budgets_for_periods
|
||||||
# For each month in the time span
|
# For each month in the time span
|
||||||
months.each do |month|
|
months.each do |month|
|
||||||
|
|||||||
@@ -127,7 +127,39 @@ class RetainerDeliverableTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
# context "#overhead_spent_for_date"
|
# context "#overhead_spent_for_date"
|
||||||
# context "#overhead_budget_total_for_date"
|
|
||||||
|
context "#overhead_budget_total_for_date" do
|
||||||
|
setup do
|
||||||
|
@deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31')
|
||||||
|
@deliverable.overhead_budgets << OverheadBudget.spawn(:budget => 100, :hours => 10)
|
||||||
|
@deliverable.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a empty period" do
|
||||||
|
should "use all periods" do
|
||||||
|
assert_equal 300.0, @deliverable.overhead_budget_total_for_date(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a period out of the retainer range" do
|
||||||
|
should "filter the records" do
|
||||||
|
assert_equal 0, @deliverable.overhead_budget_total_for_date(Date.new(2011,1,1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with an invalid period" do
|
||||||
|
should "return 0" do
|
||||||
|
assert_equal 0, @deliverable.overhead_budget_total_for_date('1')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a period in the retainer range" do
|
||||||
|
should "filter the records" do
|
||||||
|
assert_equal 100.0, @deliverable.overhead_budget_total_for_date(Date.new(2010,2,1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# context "#profit_left_for_date"
|
# context "#profit_left_for_date"
|
||||||
# context "#profit_budget_for_date"
|
# context "#profit_budget_for_date"
|
||||||
# context "#total_spent_for_date"
|
# context "#total_spent_for_date"
|
||||||
|
|||||||
Reference in new issue
Block a user