Defect #20995 » calculate_done_ratio_from_children_20995.diff
app/models/issue.rb | ||
---|---|---|
1511 | 1511 |
if p.done_ratio_derived? |
1512 | 1512 |
# done ratio = weighted average ratio of leaves |
1513 | 1513 |
unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio |
1514 |
leaves_count = p.leaves.count
|
|
1515 |
if leaves_count > 0
|
|
1516 |
average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f
|
|
1514 |
child_count = p.children.count
|
|
1515 |
if child_count > 0
|
|
1516 |
average = p.children.where("estimated_hours > 0").average(:estimated_hours).to_f
|
|
1517 | 1517 |
if average == 0 |
1518 | 1518 |
average = 1 |
1519 | 1519 |
end |
1520 |
done = p.leaves.joins(:status).
|
|
1520 |
done = p.children.joins(:status).
|
|
1521 | 1521 |
sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + |
1522 | 1522 |
"* (CASE WHEN is_closed = #{self.class.connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f |
1523 |
progress = done / (average * leaves_count)
|
|
1523 |
progress = done / (average * child_count)
|
|
1524 | 1524 |
p.done_ratio = progress.round |
1525 | 1525 |
end |
1526 | 1526 |
end |
test/unit/issue_subtasking_test.rb | ||
---|---|---|
185 | 185 |
end |
186 | 186 |
end |
187 | 187 | |
188 |
def test_done_ratio_of_parent_should_reflect_children |
|
189 |
root = Issue.generate! |
|
190 |
child1 = root.generate_child! |
|
191 |
child2 = child1.generate_child! |
|
192 | ||
193 |
assert_equal 0, root.done_ratio |
|
194 |
assert_equal 0, child1.done_ratio |
|
195 |
assert_equal 0, child2.done_ratio |
|
196 | ||
197 |
with_settings :issue_done_ratio => 'issue_status' do |
|
198 |
status = IssueStatus.find(4) |
|
199 |
status.update_attribute :default_done_ratio, 50 |
|
200 |
child1.update_attribute :status, status |
|
201 | ||
202 |
assert_equal 50, child1.done_ratio |
|
203 |
root.reload |
|
204 |
assert_equal 50, root.done_ratio |
|
205 |
end |
|
206 |
end |
|
207 | ||
188 | 208 |
def test_parent_dates_should_be_editable_with_parent_issue_dates_set_to_independent |
189 | 209 |
with_settings :parent_issue_dates => 'independent' do |
190 | 210 |
issue = Issue.generate_with_child! |