[#4420] Retainers extended past the end date will duplicate the month's last budget items.

This commit is contained in:
Eric Davis committed 2010-09-01 15:09:36 -07:00
1 parent c12a33e25d
commit 16f8152599
2 files changed
+62

No files matched your search

+22
View File
@@ -14,6 +14,7 @@ class RetainerDeliverable < HourlyDeliverable
# Accessors
# Callbacks
before_update :check_for_extended_period
def short_type
'R'
@@ -72,6 +73,27 @@ class RetainerDeliverable < HourlyDeliverable
overhead_budgets.all(:conditions => ["#{OverheadBudget.table_name}.year IS NULL AND #{OverheadBudget.table_name}.month IS NULL"]).collect(&:destroy)
end
def check_for_extended_period
# TODO: brute force. Alternative would be to check end_date_changes to see if the period actually shifted
if end_date_changed?
last_labor_budget = labor_budgets.last(:order => 'year ASC, month ASC')
last_overhead_budget = overhead_budgets.last(:order => 'year ASC, month ASC')
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(last_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(last_overhead_budget.attributes.except('id').merge('year' => new_date.year, 'month' => new_date.month))
end
end
end
end
def self.frequencies_to_select
ValidFrequencies.collect {|f| [l("text_#{f}"), f]}
end