]> source.dussan.org Git - redmine.git/commitdiff
Calculate done_ratio based on children instead of leaves (#20995).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Nov 2015 09:58:52 +0000 (09:58 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Nov 2015 09:58:52 +0000 (09:58 +0000)
Patch by Jens Krämer.

git-svn-id: http://svn.redmine.org/redmine/trunk@14875 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_subtasking_test.rb

index 5da5f4d50efa6d80f5ba53addcc25a9f900927b2..707c4581c158ec9214d21f9549f8a547895637f0 100644 (file)
@@ -1529,16 +1529,16 @@ class Issue < ActiveRecord::Base
       if p.done_ratio_derived?
         # done ratio = weighted average ratio of leaves
         unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
-          leaves_count = p.leaves.count
-          if leaves_count > 0
-            average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f
+          child_count = p.children.count
+          if child_count > 0
+            average = p.children.where("estimated_hours > 0").average(:estimated_hours).to_f
             if average == 0
               average = 1
             end
-            done = p.leaves.joins(:status).
+            done = p.children.joins(:status).
               sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " +
                   "* (CASE WHEN is_closed = #{self.class.connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f
-            progress = done / (average * leaves_count)
+            progress = done / (average * child_count)
             p.done_ratio = progress.round
           end
         end
index 7814d34b1ae6ae224d25a9b18ceb8ef14143995d..cadfe6644e538659ebb92e763489973e4c47e663 100644 (file)
@@ -185,6 +185,26 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
     end
   end
 
+  def test_done_ratio_of_parent_should_reflect_children
+    root = Issue.generate!
+    child1 = root.generate_child!
+    child2 = child1.generate_child!
+
+    assert_equal 0, root.done_ratio
+    assert_equal 0, child1.done_ratio
+    assert_equal 0, child2.done_ratio
+
+    with_settings :issue_done_ratio => 'issue_status' do
+      status = IssueStatus.find(4)
+      status.update_attribute :default_done_ratio, 50
+      child1.update_attribute :status, status
+
+      assert_equal 50, child1.done_ratio
+      root.reload
+      assert_equal 50, root.done_ratio
+    end
+  end
+
   def test_parent_dates_should_be_editable_with_parent_issue_dates_set_to_independent
     with_settings :parent_issue_dates => 'independent' do
       issue = Issue.generate_with_child!