[#4420] Retainers extended before the start date will duplicate the month's first budget items.

This commit is contained in:
Eric Davis
2010-09-01 15:15:16 -07:00
parent 16f8152599
commit 4b12d9d9c8
2 changed files with 59 additions and 0 deletions
+19
View File
@@ -92,6 +92,25 @@ class RetainerDeliverable < HourlyDeliverable
end
end
# TODO: brute force. Alternative would be to check start_date_changes to see if the period actually shifted
if start_date_changed?
first_labor_budget = labor_budgets.first(:order => 'year DESC, month DESC')
first_overhead_budget = overhead_budgets.first(:order => 'year DESC, month DESC')
months.each do |new_date|
existing_labor = labor_budgets.first(:conditions => {:year => new_date.year, :month => new_date.month})
unless existing_labor
labor_budgets.create(first_labor_budget.attributes.except('id').merge('year' => new_date.year, 'month' => new_date.month))
end
existing_overhead = overhead_budgets.first(:conditions => {:year => new_date.year, :month => new_date.month})
unless existing_overhead
overhead_budgets.create(first_overhead_budget.attributes.except('id').merge('year' => new_date.year, 'month' => new_date.month))
end
end
end
end
def self.frequencies_to_select
@@ -198,4 +198,44 @@ class DeliverablesEditTest < ActionController::IntegrationTest
end
end
should "allow extending a Retainer's start additional months" do
@retainer_deliverable = RetainerDeliverable.spawn(:contract => @contract, :manager => @manager, :title => "Retainer")
@retainer_deliverable.labor_budgets << @labor_budget = LaborBudget.spawn(:deliverable => @retainer_deliverable, :budget => 1000, :hours => 10)
@retainer_deliverable.overhead_budgets << @overhead_budget = OverheadBudget.spawn(:deliverable => @retainer_deliverable, :budget => 1000, :hours => 10)
@retainer_deliverable.start_date = '2010-01-01'
@retainer_deliverable.end_date = '2010-12-31'
@retainer_deliverable.save!
assert_equal 12, @retainer_deliverable.months.length
@first_labor_budget = @retainer_deliverable.labor_budgets.first
@first_overhead_budget = @retainer_deliverable.overhead_budgets.first
visit_contract_page(@contract)
click_link_within "#deliverable_details_#{@retainer_deliverable.id}", 'Edit'
assert_response :success
assert_template 'deliverables/edit'
# Extend the period
fill_in "Start", :with => '2009-01-13' # 12 new months
click_button "Save"
assert_response :success
assert_template 'contracts/show'
@labor_budgets = @retainer_deliverable.reload.labor_budgets
assert_equal 24, @labor_budgets.length
@labor_budgets[0,12].each do |labor_budget| # First 12
assert_equal @first_labor_budget.hours, labor_budget.hours
assert_equal @first_labor_budget.budget, labor_budget.budget
end
@overhead_budgets = @retainer_deliverable.reload.overhead_budgets
assert_equal 24, @overhead_budgets.length
@overhead_budgets[0,12].each do |overhead_budget| # First 12
assert_equal @first_overhead_budget.hours, overhead_budget.hours
assert_equal @first_overhead_budget.budget, overhead_budget.budget
end
end
end