@@ -1,106 +1,106 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Version < ActiveRecord::Base |
|
18 | class Version < ActiveRecord::Base | |
19 | before_destroy :check_integrity |
|
19 | before_destroy :check_integrity | |
20 | belongs_to :project |
|
20 | belongs_to :project | |
21 | has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id' |
|
21 | has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id' | |
22 | has_many :attachments, :as => :container, :dependent => :destroy |
|
22 | has_many :attachments, :as => :container, :dependent => :destroy | |
23 |
|
23 | |||
24 | validates_presence_of :name |
|
24 | validates_presence_of :name | |
25 | validates_uniqueness_of :name, :scope => [:project_id] |
|
25 | validates_uniqueness_of :name, :scope => [:project_id] | |
26 | validates_length_of :name, :maximum => 60 |
|
26 | validates_length_of :name, :maximum => 60 | |
27 | validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date, :allow_nil => true |
|
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 | def start_date |
|
29 | def start_date | |
30 | effective_date |
|
30 | effective_date | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def due_date |
|
33 | def due_date | |
34 | effective_date |
|
34 | effective_date | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | # Returns the total estimated time for this version |
|
37 | # Returns the total estimated time for this version | |
38 | def estimated_hours |
|
38 | def estimated_hours | |
39 | @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f |
|
39 | @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | # Returns the total reported time for this version |
|
42 | # Returns the total reported time for this version | |
43 | def spent_hours |
|
43 | def spent_hours | |
44 | @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f |
|
44 | @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | # Returns true if the version is completed: due date reached and no open issues |
|
47 | # Returns true if the version is completed: due date reached and no open issues | |
48 | def completed? |
|
48 | def completed? | |
49 | effective_date && (effective_date <= Date.today) && (open_issues_count == 0) |
|
49 | effective_date && (effective_date <= Date.today) && (open_issues_count == 0) | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def completed_pourcent |
|
52 | def completed_pourcent | |
53 | if fixed_issues.count == 0 |
|
53 | if fixed_issues.count == 0 | |
54 | 0 |
|
54 | 0 | |
55 | elsif open_issues_count == 0 |
|
55 | elsif open_issues_count == 0 | |
56 | 100 |
|
56 | 100 | |
57 | else |
|
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 | end |
|
59 | end | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def closed_pourcent |
|
62 | def closed_pourcent | |
63 | if fixed_issues.count == 0 |
|
63 | if fixed_issues.count == 0 | |
64 | 0 |
|
64 | 0 | |
65 | else |
|
65 | else | |
66 | closed_issues_count * 100.0 / fixed_issues.count |
|
66 | closed_issues_count * 100.0 / fixed_issues.count | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | # Returns true if the version is overdue: due date reached and some open issues |
|
70 | # Returns true if the version is overdue: due date reached and some open issues | |
71 | def overdue? |
|
71 | def overdue? | |
72 | effective_date && (effective_date < Date.today) && (open_issues_count > 0) |
|
72 | effective_date && (effective_date < Date.today) && (open_issues_count > 0) | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def open_issues_count |
|
75 | def open_issues_count | |
76 | @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status) |
|
76 | @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status) | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def closed_issues_count |
|
79 | def closed_issues_count | |
80 | @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status) |
|
80 | @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status) | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def wiki_page |
|
83 | def wiki_page | |
84 | if project.wiki && !wiki_page_title.blank? |
|
84 | if project.wiki && !wiki_page_title.blank? | |
85 | @wiki_page ||= project.wiki.find_page(wiki_page_title) |
|
85 | @wiki_page ||= project.wiki.find_page(wiki_page_title) | |
86 | end |
|
86 | end | |
87 | @wiki_page |
|
87 | @wiki_page | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def to_s; name end |
|
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 | # Those with no effective_date are at the end, sorted by name |
|
93 | # Those with no effective_date are at the end, sorted by name | |
94 | def <=>(version) |
|
94 | def <=>(version) | |
95 | if self.effective_date |
|
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 | else |
|
97 | else | |
98 | version.effective_date ? 1 : (self.name <=> version.name) |
|
98 | version.effective_date ? 1 : (self.name <=> version.name) | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | private |
|
102 | private | |
103 | def check_integrity |
|
103 | def check_integrity | |
104 | raise "Can't delete version" if self.fixed_issues.find(:first) |
|
104 | raise "Can't delete version" if self.fixed_issues.find(:first) | |
105 | end |
|
105 | end | |
106 | end |
|
106 | end |
General Comments 0
You need to be logged in to leave comments.
Login now