comparison app/models/time_entry.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children e248c7af89ec
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
28 28
29 acts_as_customizable 29 acts_as_customizable
30 acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"}, 30 acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
31 :url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}}, 31 :url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}},
32 :author => :user, 32 :author => :user,
33 :group => :issue,
33 :description => :comments 34 :description => :comments
34 35
35 acts_as_activity_provider :timestamp => "#{table_name}.created_on", 36 acts_as_activity_provider :timestamp => "#{table_name}.created_on",
36 :author_key => :user_id, 37 :author_key => :user_id,
37 :find_options => {:include => :project} 38 :find_options => {:include => :project}
38 39
39 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on 40 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
40 validates_numericality_of :hours, :allow_nil => true, :message => :invalid 41 validates_numericality_of :hours, :allow_nil => true, :message => :invalid
41 validates_length_of :comments, :maximum => 255, :allow_nil => true 42 validates_length_of :comments, :maximum => 255, :allow_nil => true
43 validates :spent_on, :date => true
42 before_validation :set_project_if_nil 44 before_validation :set_project_if_nil
43 validate :validate_time_entry 45 validate :validate_time_entry
44 46
45 scope :visible, lambda {|*args| { 47 scope :visible, lambda {|*args|
46 :include => :project, 48 includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args))
47 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args) 49 }
48 }} 50 scope :on_issue, lambda {|issue|
49 scope :on_issue, lambda {|issue| { 51 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}")
50 :include => :issue, 52 }
51 :conditions => "#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}" 53 scope :on_project, lambda {|project, include_subprojects|
52 }} 54 includes(:project).where(project.project_condition(include_subprojects))
53 scope :on_project, lambda {|project, include_subprojects| { 55 }
54 :include => :project,
55 :conditions => project.project_condition(include_subprojects)
56 }}
57 scope :spent_between, lambda {|from, to| 56 scope :spent_between, lambda {|from, to|
58 if from && to 57 if from && to
59 {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]} 58 where("#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to)
60 elsif from 59 elsif from
61 {:conditions => ["#{TimeEntry.table_name}.spent_on >= ?", from]} 60 where("#{TimeEntry.table_name}.spent_on >= ?", from)
62 elsif to 61 elsif to
63 {:conditions => ["#{TimeEntry.table_name}.spent_on <= ?", to]} 62 where("#{TimeEntry.table_name}.spent_on <= ?", to)
64 else 63 else
65 {} 64 where(nil)
66 end 65 end
67 } 66 }
68 67
69 safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields' 68 safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields'
70 69