Project

General

Profile

Defect #23511 » 0002-fix-attempt-for-23511.patch

Jens Krämer, 2016-08-23 04:33

View differences:

app/models/issue.rb
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
average = (p.total_estimated_hours || 0) / child_count
if average == 0
average = 1
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
done = p.children.inject(0) do |sum, c|
done_ratio = c.closed? ? 100 : (c.done_ratio || 0)
total = c.total_estimated_hours
if total.nil? || total == 0
sum + average * done_ratio
else
sum + (total * done_ratio)
end
end
progress = done / (average * child_count)
p.done_ratio = progress.round
end
(3-3/3)