diff --git a/app/models/issue.rb b/app/models/issue.rb index 295cedbc8..abf4cec92 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1338,7 +1338,7 @@ class Issue < ActiveRecord::Base def recalculate_attributes_for(issue_id) if issue_id && p = Issue.find_by_id(issue_id) # priority = highest priority of children - if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :joins => :priority) + if priority_position = p.children.joins(:priority).maximum("#{IssuePriority.table_name}.position") p.priority = IssuePriority.find_by_position(priority_position) end @@ -1357,8 +1357,9 @@ class Issue < ActiveRecord::Base if average == 0 average = 1 end - done = p.leaves.sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + - "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f + done = p.leaves.joins(:status). + sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + + "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f progress = done / (average * leaves_count) p.done_ratio = progress.round end