]> source.dussan.org Git - redmine.git/commitdiff
Done ratio of a parent issue may be shown as 99% even though all subtasks are complet...
authorGo MAEDA <maeda@farend.jp>
Sun, 14 Jun 2020 06:56:05 +0000 (06:56 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 14 Jun 2020 06:56:05 +0000 (06:56 +0000)
Patch by Go MAEDA.

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

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

index e665a46cb051fc53a17e6b6afe5290a748db5147..a89f23dd8d395f9139ffb46ac177bb773e52e6be 100644 (file)
@@ -1731,12 +1731,12 @@ class Issue < ActiveRecord::Base
           if children.any?
             child_with_total_estimated_hours = children.select {|c| c.total_estimated_hours.to_f > 0.0}
             if child_with_total_estimated_hours.any?
-              average = child_with_total_estimated_hours.map(&:total_estimated_hours).sum.to_f / child_with_total_estimated_hours.count
+              average = child_with_total_estimated_hours.map(&:total_estimated_hours).sum.to_d / child_with_total_estimated_hours.count
             else
-              average = 1.0
+              average = 1.0.to_d
             end
             done = children.map {|c|
-              estimated = c.total_estimated_hours.to_f
+              estimated = (c.total_estimated_hours || 0.0).to_d
               estimated = average unless estimated > 0.0
               ratio = c.closed? ? 100 : (c.done_ratio || 0)
               estimated * ratio
index 85772909b8b8131424bd0ddd570d473bd705f529..2826162f66f6e1881cd894099eb63d8698820dc9 100644 (file)
@@ -241,6 +241,16 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
     end
   end
 
+  def test_done_ratio_of_parent_with_completed_children_should_not_be_99
+    with_settings :parent_issue_done_ratio => 'derived' do
+      parent = Issue.generate!
+      parent.generate_child!(:estimated_hours => 8.0, :done_ratio => 100)
+      parent.generate_child!(:estimated_hours => 8.1, :done_ratio => 100)
+      # (8.0 * 100 + 8.1 * 100) / (8.0 + 8.1) => 99.99999999999999
+      assert_equal 100, parent.reload.done_ratio
+    end
+  end
+
   def test_changing_parent_should_update_previous_parent_done_ratio
     with_settings :parent_issue_done_ratio => 'derived' do
       first_parent = Issue.generate!