5 |
5 |
# modify it under the terms of the GNU General Public License
|
6 |
6 |
# as published by the Free Software Foundation; either version 2
|
7 |
7 |
# of the License, or (at your option) any later version.
|
8 |
|
#
|
|
8 |
#
|
9 |
9 |
# This program is distributed in the hope that it will be useful,
|
10 |
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
12 |
# GNU General Public License for more details.
|
13 |
|
#
|
|
13 |
#
|
14 |
14 |
# You should have received a copy of the GNU General Public License
|
15 |
15 |
# along with this program; if not, write to the Free Software
|
16 |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
... | ... | |
25 |
25 |
validates_uniqueness_of :name, :scope => [:project_id]
|
26 |
26 |
validates_length_of :name, :maximum => 60
|
27 |
27 |
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => 'activerecord_error_not_a_date', :allow_nil => true
|
28 |
|
|
|
28 |
|
29 |
29 |
def start_date
|
30 |
30 |
effective_date
|
31 |
31 |
end
|
32 |
|
|
|
32 |
|
33 |
33 |
def due_date
|
34 |
34 |
effective_date
|
35 |
35 |
end
|
... | ... | |
48 |
48 |
def completed?
|
49 |
49 |
effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
|
50 |
50 |
end
|
51 |
|
|
|
51 |
|
52 |
52 |
def completed_pourcent
|
53 |
53 |
if fixed_issues.count == 0
|
54 |
54 |
0
|
55 |
55 |
elsif open_issues_count == 0
|
56 |
56 |
100
|
57 |
57 |
else
|
58 |
|
(closed_issues_count * 100 + Issue.sum('done_ratio', :include => 'status', :conditions => ["fixed_version_id = ? AND is_closed = ?", id, false]).to_f) / fixed_issues.count
|
|
58 |
# (closed_issues_count * 100 + Issue.sum('done_ratio', :include => 'status', :conditions => ["fixed_version_id = ? AND is_closed = ?", id, false]).to_f) / fixed_issues.count
|
|
59 |
calculate_percent_from_hours
|
59 |
60 |
end
|
60 |
61 |
end
|
61 |
|
|
|
62 |
|
62 |
63 |
def closed_pourcent
|
63 |
64 |
if fixed_issues.count == 0
|
64 |
65 |
0
|
... | ... | |
71 |
72 |
def overdue?
|
72 |
73 |
effective_date && (effective_date < Date.today) && (open_issues_count > 0)
|
73 |
74 |
end
|
74 |
|
|
|
75 |
|
75 |
76 |
def open_issues_count
|
76 |
77 |
@open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status)
|
77 |
78 |
end
|
... | ... | |
79 |
80 |
def closed_issues_count
|
80 |
81 |
@closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status)
|
81 |
82 |
end
|
82 |
|
|
|
83 |
|
83 |
84 |
def wiki_page
|
84 |
85 |
if project.wiki && !wiki_page_title.blank?
|
85 |
86 |
@wiki_page ||= project.wiki.find_page(wiki_page_title)
|
86 |
87 |
end
|
87 |
88 |
@wiki_page
|
88 |
89 |
end
|
89 |
|
|
|
90 |
|
90 |
91 |
def to_s; name end
|
91 |
|
|
92 |
92 |
# Versions are sorted by effective_date and name
|
93 |
93 |
# Those with no effective_date are at the end, sorted by name
|
94 |
94 |
def <=>(version)
|
... | ... | |
98 |
98 |
version.effective_date ? 1 : (self.name <=> version.name)
|
99 |
99 |
end
|
100 |
100 |
end
|
101 |
|
|
|
101 |
|
102 |
102 |
private
|
103 |
103 |
def check_integrity
|
104 |
104 |
raise "Can't delete version" if self.fixed_issues.find(:first)
|
105 |
105 |
end
|
|
106 |
|
|
107 |
# Calculates the % complete on a project based off the total esimated
|
|
108 |
# time left on the issues divided by the total time
|
|
109 |
def calculate_percent_from_hours
|
|
110 |
spent = 0
|
|
111 |
total = 0
|
|
112 |
Issue.find(:all, :include => 'status', :conditions => ["fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", id, false]).each do |i|
|
|
113 |
unless i.estimated_hours.nil?
|
|
114 |
spent += i.estimated_hours * i.done_ratio
|
|
115 |
total += i.estimated_hours
|
|
116 |
end
|
|
117 |
end
|
|
118 |
|
|
119 |
Issue.find(:all, :conditions => ["fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", id, true], :include => :status).each do |i|
|
|
120 |
unless i.estimated_hours.nil?
|
|
121 |
spent += i.estimated_hours * 100
|
|
122 |
total += i.estimated_hours
|
|
123 |
end
|
|
124 |
end
|
|
125 |
|
|
126 |
if spent == 0 and total == 0
|
|
127 |
# Redmine default
|
|
128 |
return (closed_issues_count * 100 + Issue.sum('done_ratio', :include => 'status', :conditions => ["fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", id, false]).to_f) / fixed_issues.count
|
|
129 |
else
|
|
130 |
return spent / total
|
|
131 |
end
|
|
132 |
end
|
106 |
133 |
end
|