From 29d4018bce6528199093f5cbdcef8bcfa42fac67 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Thu, 18 Aug 2016 13:30:13 +0800 Subject: [PATCH 2/2] fix attempt for 23511 - based on the original description of the issue - fixes the original problem - breaks 2 other subtasking tests where child issues have no estimated times --- app/models/issue.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 0b8a2b2..a7742ce 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1556,13 +1556,19 @@ class Issue < ActiveRecord::Base 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 -- 2.1.4