[#4604] Clear and recalculate the #cost on Rate#save

This commit is contained in:
Eric Davis
2010-10-06 13:05:57 -07:00
parent d656121b20
commit f7b03b825f
3 changed files with 38 additions and 1 deletions
+11 -1
View File
@@ -17,7 +17,16 @@ module RateTimeEntryPatch
end
module ClassMethods
# Updated the cached cost of all TimeEntries for user and project
def update_cost_cache(user, project=nil)
c = ARCondition.new
c << ["#{TimeEntry.table_name}.user_id = ?", user]
c << ["#{TimeEntry.table_name}.project_id = ?", project] if project
TimeEntry.all(:conditions => c.conditions).each do |time_entry|
time_entry.save_cached_cost
end
end
end
module InstanceMethods
@@ -53,6 +62,7 @@ module RateTimeEntryPatch
end
def save_cached_cost
clear_cost_cache
update_attribute(:cost, cost)
end