]> source.dussan.org Git - redmine.git/commitdiff
Progress of version should be calculated the same way as parent tasks (#24457, #4682).
authorMarius Balteanu <marius.balteanu@zitec.com>
Thu, 2 May 2024 20:58:03 +0000 (20:58 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Thu, 2 May 2024 20:58:03 +0000 (20:58 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@22803 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/version.rb
test/unit/version_test.rb

index 17e1128e488d29b37ca64a0b79efabaff2757c07..e1525f9a0cbb15deb0d0235c58ba7a2894ad39da 100644 (file)
@@ -78,9 +78,11 @@ module FixedIssuesExtension
   # Used to weight unestimated issues in progress calculation
   def estimated_average
     if @estimated_average.nil?
-      average = average(:estimated_hours).to_f
-      if average == 0
-        average = 1
+      issues_with_total_estimated_hours = select {|c| c.total_estimated_hours.to_f > 0.0}
+      if issues_with_total_estimated_hours.any?
+        average = issues_with_total_estimated_hours.map(&:total_estimated_hours).sum.to_f / issues_with_total_estimated_hours.count
+      else
+        average = 1.0
       end
       @estimated_average = average
     end
@@ -98,9 +100,12 @@ module FixedIssuesExtension
     @issues_progress[open] ||= begin
       progress = 0
       if count > 0
-        ratio = open ? 'done_ratio' : 100
-
-        done = open(open).sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}").to_f
+        done = open(open).map {|c|
+          estimated = c.total_estimated_hours.to_f
+          estimated = estimated_average unless estimated > 0.0
+          ratio = c.closed? ? 100 : (c.done_ratio || 0)
+          estimated * ratio
+        }.sum
         progress = done / (estimated_average * count)
       end
       progress
index 45c5bed3734f32ae35fa34181031ec86a2f124f3..4b20c05a0062550c78726455000cf5cde743c0ac 100644 (file)
@@ -117,6 +117,16 @@ class VersionTest < ActiveSupport::TestCase
     assert_progress_equal (100.0)/3, v.closed_percent
   end
 
+  def test_progress_should_consider_closed_issues_with_0h_estimated_as_completed
+    project = Project.find(1)
+    closed = IssueStatus.where(:is_closed => true).first
+    v = Version.create!(:project => project, :name => 'Progress')
+    add_issue(v, :done_ratio => 100, :estimated_hours => 0)
+    add_issue(v, :done_ratio => 100, :estimated_hours => 0, :status => closed)
+    assert_progress_equal 100, v.completed_percent
+    assert_progress_equal 50, v.closed_percent
+  end
+
   def test_progress_should_consider_estimated_hours_to_weight_issues
     project = Project.find(1)
     v = Version.create!(:project => project, :name => 'Progress')