]> source.dussan.org Git - redmine.git/commitdiff
The done ratio of a parent issue may not be 100% even if all subtasks have a done...
authorGo MAEDA <maeda@farend.jp>
Wed, 8 Jun 2022 15:40:45 +0000 (15:40 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 8 Jun 2022 15:40:45 +0000 (15:40 +0000)
Patch by Go MAEDA.

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

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

index 73fd3f8cd586a2c3a0dbc1a822ed1fefc40503d5..1ad09e0aafe7e3ac9cdaa409ccebdc5103729e3b 100644 (file)
@@ -1838,19 +1838,20 @@ 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.sum(&:total_estimated_hours).to_d /
-                  child_with_total_estimated_hours.count
+              average = Rational(
+                child_with_total_estimated_hours.sum(&:total_estimated_hours).to_s,
+                child_with_total_estimated_hours.count
+              )
             else
-              average = BigDecimal('1.0')
+              average = Rational(1)
             end
             done = children.sum do |c|
-              estimated = (c.total_estimated_hours || 0.0).to_d
+              estimated = Rational(c.total_estimated_hours.to_f.to_s)
               estimated = average unless estimated > 0.0
               ratio = c.closed? ? 100 : (c.done_ratio || 0)
               estimated * ratio
             end
-            progress = done / (average * children.count)
+            progress = Rational(done, average * children.count)
             p.done_ratio = progress.floor
           end
         end
index 0c2ffaa4d885b2c86cb0f01feb83fd6c1b9b58dd..0710190fd04d658121896cfd813133d80bcd3b26 100644 (file)
@@ -243,11 +243,18 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
 
   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)
+      parent1 = Issue.generate!
+      parent1.generate_child!(:estimated_hours => 8.0, :done_ratio => 100)
+      parent1.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
+      assert_equal 100, parent1.reload.done_ratio
+
+      parent2 = Issue.generate!
+      parent2.generate_child!(:estimated_hours => 9.0, :done_ratio => 100)
+      10.times do
+        parent2.generate_child!(:estimated_hours => 10.0, :done_ratio => 100)
+      end
+      assert_equal 100, parent2.reload.done_ratio
     end
   end