Defect #24213 ยป done_fixed_for_several_levels_of_subtasks.diff
| app/models/issue.rb | ||
|---|---|---|
| 1549 | 1549 |
unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio |
| 1550 | 1550 |
child_count = p.children.count |
| 1551 | 1551 |
if child_count > 0 |
| 1552 |
average = p.children.where("estimated_hours > 0").average(:estimated_hours).to_f
|
|
| 1553 |
if average == 0 |
|
| 1554 |
average = 1 |
|
| 1552 |
# Calculate the average hours for all child tasks using the childrens total_estimated_hours. |
|
| 1553 |
sum = 0 |
|
| 1554 |
p.children.each do |child| |
|
| 1555 |
sum += child.total_estimated_hours |
|
| 1555 | 1556 |
end |
| 1556 |
done = p.children.joins(:status). |
|
| 1557 |
sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " +
|
|
| 1558 |
"* (CASE WHEN is_closed = #{self.class.connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f
|
|
| 1559 |
progress = done / (average * child_count) |
|
| 1557 |
if sum == 0 |
|
| 1558 |
average_hours = 1 |
|
| 1559 |
else |
|
| 1560 |
average_hours = sum / child_count |
|
| 1561 |
end |
|
| 1562 | ||
| 1563 |
# Calculate the total work done for the children |
|
| 1564 |
# Each child contribute to the total work with its total_estimate_hours multiplied |
|
| 1565 |
# by its done_ratio or 100 if the child is closed. |
|
| 1566 |
# If the childs total_estiamted_hours is zero then use the average_hours for |
|
| 1567 |
# that child. |
|
| 1568 |
done = 0 |
|
| 1569 |
p.children.each do |child| |
|
| 1570 |
child_hours = child.total_estimated_hours |
|
| 1571 |
if child_hours == 0 then |
|
| 1572 |
child_hours = average_hours |
|
| 1573 |
end |
|
| 1574 |
# calculate the contribution to done for the child |
|
| 1575 |
if child.closed? then |
|
| 1576 |
done += child_hours * 100 |
|
| 1577 |
else |
|
| 1578 |
done += child_hours * child.done_ratio |
|
| 1579 |
end |
|
| 1580 |
end |
|
| 1581 | ||
| 1582 |
# Calculate the progress |
|
| 1583 |
progress = done / (average_hours * child_count) |
|
| 1560 | 1584 |
p.done_ratio = progress.round |
| 1561 | 1585 |
end |
| 1562 | 1586 |
end |