@@ -1,106 +1,106 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
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. |
|
17 | 17 | |
|
18 | 18 | class Version < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | belongs_to :project |
|
21 | 21 | has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id' |
|
22 | 22 | has_many :attachments, :as => :container, :dependent => :destroy |
|
23 | 23 | |
|
24 | 24 | validates_presence_of :name |
|
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 |
|
36 | 36 | |
|
37 | 37 | # Returns the total estimated time for this version |
|
38 | 38 | def estimated_hours |
|
39 | 39 | @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | # Returns the total reported time for this version |
|
43 | 43 | def spent_hours |
|
44 | 44 | @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | # Returns true if the version is completed: due date reached and no open issues |
|
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 | 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 | 59 | end |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def closed_pourcent |
|
63 | 63 | if fixed_issues.count == 0 |
|
64 | 64 | 0 |
|
65 | 65 | else |
|
66 | 66 | closed_issues_count * 100.0 / fixed_issues.count |
|
67 | 67 | end |
|
68 | 68 | end |
|
69 | 69 | |
|
70 | 70 | # Returns true if the version is overdue: due date reached and some open issues |
|
71 | 71 | def overdue? |
|
72 | 72 | effective_date && (effective_date < Date.today) && (open_issues_count > 0) |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def open_issues_count |
|
76 | 76 | @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status) |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def closed_issues_count |
|
80 | 80 | @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status) |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def wiki_page |
|
84 | 84 | if project.wiki && !wiki_page_title.blank? |
|
85 | 85 | @wiki_page ||= project.wiki.find_page(wiki_page_title) |
|
86 | 86 | end |
|
87 | 87 | @wiki_page |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def to_s; name end |
|
91 | 91 | |
|
92 | # Versions are sorted by effective_date | |
|
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) |
|
95 | 95 | if self.effective_date |
|
96 | version.effective_date ? (self.effective_date <=> version.effective_date) : -1 | |
|
96 | version.effective_date ? (self.effective_date == version.effective_date ? self.name <=> version.name : self.effective_date <=> version.effective_date) : -1 | |
|
97 | 97 | else |
|
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 | 106 | end |
General Comments 0
You need to be logged in to leave comments.
Login now