introduce inheritance of HourlyRates from project ancestors. This currently works only for Redmine 0.8.x

fixes #10617

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@134 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
hjust 15 years ago
parent 368f546594
commit 671a71e33e
  1. 12
      lib/user_patch.rb

@ -24,12 +24,16 @@ module UserPatch
end
module InstanceMethods
def current_rate(project_id, include_default = true)
rate_at(Date.today, project_id, include_default)
def current_rate(project, include_default = true)
rate_at(Date.today, project, include_default)
end
def rate_at(date, project_id, include_default = true)
rate = HourlyRate.find(:first, :conditions => [ "user_id = ? and project_id = ? and valid_from <= ?", id, project_id, date], :order => "valid_from DESC")
def rate_at(date, project, include_default = true)
project = Project.find(project) unless project.is_a?(Project)
rate = HourlyRate.find(:first, :conditions => [ "user_id = ? and project_id = ? and valid_from <= ?", id, project, date], :order => "valid_from DESC")
# TODO: this is Redmine 0.8 specific. Sort by project.lft first if using redmine 0.9!
rate ||= HourlyRate.find(:first, :conditions => [ "user_id = ? and project_id in (?) and valid_from <= ?", id, project.ancestors, date], :order => "valid_from DESC")
rate ||= default_rate_at(date) if include_default
rate
end

Loading…
Cancel
Save