Project

General

Profile

Feature #2182 » version_completion.patch

Jean-Philippe Lang, 2008-11-14 18:48

View differences:

app/models/version.rb (copie de travail)
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
      issues_progress(false) + issues_progress(true)
59 59
    end
60 60
  end
61 61
  
......
63 63
    if fixed_issues.count == 0
64 64
      0
65 65
    else
66
      closed_issues_count * 100.0 / fixed_issues.count
66
      issues_progress(false)
67 67
    end
68 68
  end
69 69
  
......
103 103
  def check_integrity
104 104
    raise "Can't delete version" if self.fixed_issues.find(:first)
105 105
  end
106
  
107
  def estimated_average
108
    if @estimated_average.nil?
109
      average = Issue.average(:estimated_hours,
110
                              :conditions => ["fixed_version_id = ?", id]).to_f
111
      if average == 0
112
        average = 1
113
      end
114
      @estimated_average = average
115
    end
116
    @estimated_average
117
  end
118
  
119
  def issues_progress(open)
120
    progress = 0
121
    if fixed_issues.count > 0
122
      ratio = open ? 'done_ratio' : 100
123
      done = Issue.sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}",
124
                                :include => :status,
125
                                :conditions => ["fixed_version_id = ? AND is_closed = ?", id, !open]).to_f
126
                                
127
      progress = done / (estimated_average * fixed_issues.count)
128
    end
129
    progress
130
  end
106 131
end
(2-2/4)