diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/settings_helper.rb | 9 | ||||
-rw-r--r-- | app/models/issue.rb | 35 | ||||
-rw-r--r-- | app/views/settings/_issues.html.erb | 2 |
3 files changed, 33 insertions, 13 deletions
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 0dcdbb040..5c747f0d2 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -149,6 +149,15 @@ module SettingsHelper options.map {|label, value| [l(label), value.to_s]} end + def parent_issue_done_ratio_options + options = [ + [:label_parent_task_attributes_derived, 'derived'], + [:label_parent_task_attributes_independent, 'independent'] + ] + + options.map {|label, value| [l(label), value.to_s]} + end + # Returns the options for the date_format setting def date_format_setting_options(locale) Setting::DATE_FORMATS.map do |f| diff --git a/app/models/issue.rb b/app/models/issue.rb index 7d04d1e15..2944031ac 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -432,8 +432,11 @@ class Issue < ActiveRecord::Base if priority_derived? names -= %w(priority_id) end + if done_ratio_derived? + names -= %w(done_ratio) + end unless leaf? - names -= %w(done_ratio estimated_hours) + names -= %w(estimated_hours) end names end @@ -1161,6 +1164,10 @@ class Issue < ActiveRecord::Base !leaf? && Setting.parent_issue_priority == 'derived' end + def done_ratio_derived? + !leaf? && Setting.parent_issue_done_ratio == 'derived' + end + def <=>(issue) if issue.nil? -1 @@ -1463,19 +1470,21 @@ class Issue < ActiveRecord::Base end end - # done ratio = weighted average ratio of leaves - unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio - leaves_count = p.leaves.count - if leaves_count > 0 - average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f - if average == 0 - average = 1 + if p.done_ratio_derived? + # done ratio = weighted average ratio of leaves + unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio + leaves_count = p.leaves.count + if leaves_count > 0 + average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f + if average == 0 + average = 1 + end + done = p.leaves.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 + progress = done / (average * leaves_count) + p.done_ratio = progress.round end - done = p.leaves.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 - progress = done / (average * leaves_count) - p.done_ratio = progress.round end end diff --git a/app/views/settings/_issues.html.erb b/app/views/settings/_issues.html.erb index a0dfd786c..b3533bbd1 100644 --- a/app/views/settings/_issues.html.erb +++ b/app/views/settings/_issues.html.erb @@ -28,6 +28,8 @@ <p><%= setting_select :parent_issue_dates, parent_issue_dates_options, :label => "#{l(:field_start_date)} / #{l(:field_due_date)}" %></p> <p><%= setting_select :parent_issue_priority, parent_issue_priority_options, :label => :field_priority %></p> + + <p><%= setting_select :parent_issue_done_ratio, parent_issue_done_ratio_options, :label => :field_done_ratio %></p> </div> </fieldset> |