Fixed calculation of done_ratio of parent task with child having estimated_time at 0 (#15870).

git-svn-id: http://svn.redmine.org/redmine/trunk@12745 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-01-31 17:42:46 +00:00
parent e699458b3c
commit 888823a449
2 changed files with 13 additions and 1 deletions

View File

@ -1355,7 +1355,7 @@ class Issue < ActiveRecord::Base
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.average(:estimated_hours).to_f
average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f
if average == 0
average = 1
end

View File

@ -368,6 +368,18 @@ class IssueNestedSetTest < ActiveSupport::TestCase
assert_equal 100, parent.reload.done_ratio
end
def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100
parent = Issue.generate!
Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id)
Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id)
Issue.generate!(:estimated_hours => 20, :parent_issue_id => parent.id)
Issue.generate!(:estimated_hours => 0, :parent_issue_id => parent.id)
parent.reload.children.each do |child|
child.update_attribute :status_id, 5
end
assert_equal 100, parent.reload.done_ratio
end
def test_move_parent_updates_old_parent_attributes
first_parent = Issue.generate!
second_parent = Issue.generate!