Project

General

Profile

Defect #37151 » 37151.patch

Go MAEDA, 2022-05-24 10:40

View differences:

app/models/issue.rb
1838 1838
          if children.any?
1839 1839
            child_with_total_estimated_hours = children.select {|c| c.total_estimated_hours.to_f > 0.0}
1840 1840
            if child_with_total_estimated_hours.any?
1841
              average =
1842
                child_with_total_estimated_hours.sum(&:total_estimated_hours).to_d /
1843
                  child_with_total_estimated_hours.count
1841
              average = Rational(
1842
                child_with_total_estimated_hours.sum(&:total_estimated_hours).to_s,
1843
                child_with_total_estimated_hours.count
1844
              )
1844 1845
            else
1845
              average = BigDecimal('1.0')
1846
              average = Rational(1)
1846 1847
            end
1847 1848
            done = children.sum do |c|
1848
              estimated = (c.total_estimated_hours || 0.0).to_d
1849
              estimated = Rational(c.total_estimated_hours.to_f.to_s)
1849 1850
              estimated = average unless estimated > 0.0
1850 1851
              ratio = c.closed? ? 100 : (c.done_ratio || 0)
1851 1852
              estimated * ratio
1852 1853
            end
1853
            progress = done / (average * children.count)
1854
            progress = Rational(done, average * children.count)
1854 1855
            p.done_ratio = progress.floor
1855 1856
          end
1856 1857
        end
test/unit/issue_subtasking_test.rb
243 243

  
244 244
  def test_done_ratio_of_parent_with_completed_children_should_not_be_99
245 245
    with_settings :parent_issue_done_ratio => 'derived' do
246
      parent = Issue.generate!
247
      parent.generate_child!(:estimated_hours => 8.0, :done_ratio => 100)
248
      parent.generate_child!(:estimated_hours => 8.1, :done_ratio => 100)
246
      parent1 = Issue.generate!
247
      parent1.generate_child!(:estimated_hours => 8.0, :done_ratio => 100)
248
      parent1.generate_child!(:estimated_hours => 8.1, :done_ratio => 100)
249 249
      # (8.0 * 100 + 8.1 * 100) / (8.0 + 8.1) => 99.99999999999999
250
      assert_equal 100, parent.reload.done_ratio
250
      assert_equal 100, parent1.reload.done_ratio
251

  
252
      parent2 = Issue.generate!
253
      parent2.generate_child!(:estimated_hours => 9.0, :done_ratio => 100)
254
      10.times do
255
        parent2.generate_child!(:estimated_hours => 10.0, :done_ratio => 100)
256
      end
257
      assert_equal 100, parent2.reload.done_ratio
251 258
    end
252 259
  end
253 260

  
(3-3/4)