mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-11 13:15:20 +00:00
Fixed that progress of parent should be calculated with total estimated hours of children (#23511).
git-svn-id: http://svn.redmine.org/redmine/trunk@15802 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a798ab4f67
commit
1324772355
@ -1553,18 +1553,23 @@ class Issue < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if p.done_ratio_derived?
|
||||
# done ratio = weighted average ratio of leaves
|
||||
# done ratio = average ratio of children weighted with their total estimated hours
|
||||
unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
|
||||
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
|
||||
children = p.children.to_a
|
||||
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
|
||||
else
|
||||
average = 1.0
|
||||
end
|
||||
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 * child_count)
|
||||
done = children.map {|c|
|
||||
estimated = c.total_estimated_hours.to_f
|
||||
estimated = average unless estimated > 0.0
|
||||
ratio = c.closed? ? 100 : (c.done_ratio || 0)
|
||||
estimated * ratio
|
||||
}.sum
|
||||
progress = done / (average * children.count)
|
||||
p.done_ratio = progress.round
|
||||
end
|
||||
end
|
||||
|
||||
@ -143,6 +143,26 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any_with_grandchildren
|
||||
# parent
|
||||
# child 1 (2h estd, 0% done)
|
||||
# child 2 (no estd)
|
||||
# child a (2h estd, 50% done)
|
||||
# child b (2h estd, 50% done)
|
||||
#
|
||||
# => parent should have a calculated progress of 33%
|
||||
#
|
||||
with_settings :parent_issue_done_ratio => 'derived' do
|
||||
parent = Issue.generate!
|
||||
parent.generate_child!(:estimated_hours => 2, :done_ratio => 0)
|
||||
child = parent.generate_child!
|
||||
child.generate_child!(:estimated_hours => 2, :done_ratio => 50)
|
||||
child.generate_child!(:estimated_hours => 2, :done_ratio => 50)
|
||||
assert_equal 50, child.reload.done_ratio
|
||||
assert_equal 33, parent.reload.done_ratio
|
||||
end
|
||||
end
|
||||
|
||||
def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100
|
||||
with_settings :parent_issue_done_ratio => 'derived' do
|
||||
parent = Issue.generate!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user