comparison app/models/version.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
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
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 VERSION_SHARINGS = %w(none descendants hierarchy tree system) 28 VERSION_SHARINGS = %w(none descendants hierarchy tree system)
29 29
30 validates_presence_of :name 30 validates_presence_of :name
31 validates_uniqueness_of :name, :scope => [:project_id] 31 validates_uniqueness_of :name, :scope => [:project_id]
32 validates_length_of :name, :maximum => 60 32 validates_length_of :name, :maximum => 60
33 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true 33 validates :effective_date, :date => true
34 validates_inclusion_of :status, :in => VERSION_STATUSES 34 validates_inclusion_of :status, :in => VERSION_STATUSES
35 validates_inclusion_of :sharing, :in => VERSION_SHARINGS 35 validates_inclusion_of :sharing, :in => VERSION_SHARINGS
36 validate :validate_version
37 36
38 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} 37 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
39 scope :open, where(:status => 'open') 38 scope :open, lambda { where(:status => 'open') }
40 scope :visible, lambda {|*args| 39 scope :visible, lambda {|*args|
41 includes(:project).where(Project.allowed_to_condition(args.first || User.current, :view_issues)) 40 includes(:project).where(Project.allowed_to_condition(args.first || User.current, :view_issues))
42 } 41 }
43 42
44 safe_attributes 'name', 43 safe_attributes 'name',
46 'effective_date', 45 'effective_date',
47 'due_date', 46 'due_date',
48 'wiki_page_title', 47 'wiki_page_title',
49 'status', 48 'status',
50 'sharing', 49 'sharing',
51 'custom_field_values' 50 'custom_field_values',
51 'custom_fields'
52 52
53 # Returns true if +user+ or current user is allowed to view the version 53 # Returns true if +user+ or current user is allowed to view the version
54 def visible?(user=User.current) 54 def visible?(user=User.current)
55 user.allowed_to?(:view_issues, self.project) 55 user.allowed_to?(:view_issues, self.project)
56 end 56 end
95 def completed? 95 def completed?
96 effective_date && (effective_date < Date.today) && (open_issues_count == 0) 96 effective_date && (effective_date < Date.today) && (open_issues_count == 0)
97 end 97 end
98 98
99 def behind_schedule? 99 def behind_schedule?
100 if completed_pourcent == 100 100 if completed_percent == 100
101 return false 101 return false
102 elsif due_date && start_date 102 elsif due_date && start_date
103 done_date = start_date + ((due_date - start_date+1)* completed_pourcent/100).floor 103 done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor
104 return done_date <= Date.today 104 return done_date <= Date.today
105 else 105 else
106 false # No issues so it's not late 106 false # No issues so it's not late
107 end 107 end
108 end 108 end
109 109
110 # Returns the completion percentage of this version based on the amount of open/closed issues 110 # Returns the completion percentage of this version based on the amount of open/closed issues
111 # and the time spent on the open issues. 111 # and the time spent on the open issues.
112 def completed_pourcent 112 def completed_percent
113 if issues_count == 0 113 if issues_count == 0
114 0 114 0
115 elsif open_issues_count == 0 115 elsif open_issues_count == 0
116 100 116 100
117 else 117 else
118 issues_progress(false) + issues_progress(true) 118 issues_progress(false) + issues_progress(true)
119 end 119 end
120 end 120 end
121 121
122 # TODO: remove in Redmine 3.0
123 def completed_pourcent
124 ActiveSupport::Deprecation.warn "Version#completed_pourcent is deprecated and will be removed in Redmine 3.0. Please use #completed_percent instead."
125 completed_percent
126 end
127
122 # Returns the percentage of issues that have been marked as 'closed'. 128 # Returns the percentage of issues that have been marked as 'closed'.
123 def closed_pourcent 129 def closed_percent
124 if issues_count == 0 130 if issues_count == 0
125 0 131 0
126 else 132 else
127 issues_progress(false) 133 issues_progress(false)
128 end 134 end
135 end
136
137 # TODO: remove in Redmine 3.0
138 def closed_pourcent
139 ActiveSupport::Deprecation.warn "Version#closed_pourcent is deprecated and will be removed in Redmine 3.0. Please use #closed_percent instead."
140 closed_percent
129 end 141 end
130 142
131 # Returns true if the version is overdue: due date reached and some open issues 143 # Returns true if the version is overdue: due date reached and some open issues
132 def overdue? 144 def overdue?
133 effective_date && (effective_date < Date.today) && (open_issues_count > 0) 145 effective_date && (effective_date < Date.today) && (open_issues_count > 0)
273 progress = done / (estimated_average * issues_count) 285 progress = done / (estimated_average * issues_count)
274 end 286 end
275 progress 287 progress
276 end 288 end
277 end 289 end
278
279 def validate_version
280 if effective_date.nil? && @attributes['effective_date'].present?
281 errors.add :effective_date, :not_a_date
282 end
283 end
284 end 290 end