Mercurial > hg > soundsoftware-site
diff app/models/time_entry.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | 433d4f72a19b |
children | e248c7af89ec |
line wrap: on
line diff
--- a/app/models/time_entry.rb Fri Jun 14 09:01:12 2013 +0100 +++ b/app/models/time_entry.rb Fri Jun 14 09:02:21 2013 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2012 Jean-Philippe Lang +# Copyright (C) 2006-2013 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -30,6 +30,7 @@ acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"}, :url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}}, :author => :user, + :group => :issue, :description => :comments acts_as_activity_provider :timestamp => "#{table_name}.created_on", @@ -39,30 +40,28 @@ validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on validates_numericality_of :hours, :allow_nil => true, :message => :invalid validates_length_of :comments, :maximum => 255, :allow_nil => true + validates :spent_on, :date => true before_validation :set_project_if_nil validate :validate_time_entry - scope :visible, lambda {|*args| { - :include => :project, - :conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args) - }} - scope :on_issue, lambda {|issue| { - :include => :issue, - :conditions => "#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}" - }} - scope :on_project, lambda {|project, include_subprojects| { - :include => :project, - :conditions => project.project_condition(include_subprojects) - }} + scope :visible, lambda {|*args| + includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)) + } + scope :on_issue, lambda {|issue| + includes(:issue).where("#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}") + } + scope :on_project, lambda {|project, include_subprojects| + includes(:project).where(project.project_condition(include_subprojects)) + } scope :spent_between, lambda {|from, to| if from && to - {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]} + where("#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to) elsif from - {:conditions => ["#{TimeEntry.table_name}.spent_on >= ?", from]} + where("#{TimeEntry.table_name}.spent_on >= ?", from) elsif to - {:conditions => ["#{TimeEntry.table_name}.spent_on <= ?", to]} + where("#{TimeEntry.table_name}.spent_on <= ?", to) else - {} + where(nil) end }