From 20c897374c4d7a977a1d72062292afe3f3431a9b Mon Sep 17 00:00:00 2001
From: Eric Davis <edavis@littlestreamsoftware.com>
Date: Tue, 6 May 2008 11:16:03 -0700
Subject: [PATCH] Adds an option which will automatically update an issue's done ratio based on
 which issue status is assigned.

---
 app/controllers/issue_statuses_controller.rb       |   11 +++-
 app/models/issue.rb                                |   19 ++++++-
 app/models/issue_status.rb                         |   12 ++++
 app/views/issue_statuses/_form.rhtml               |    5 ++
 app/views/issue_statuses/list.rhtml                |    7 ++
 app/views/issues/_form.rhtml                       |    2 +
 app/views/issues/_form_update.rhtml                |    2 +
 app/views/issues/bulk_edit.rhtml                   |    2 +
 app/views/issues/context_menu.rhtml                |    3 +-
 app/views/settings/_issues.rhtml                   |    5 ++
 config/locales/bg.yml                              |    4 +
 config/locales/bs.yml                              |    4 +
 config/locales/ca.yml                              |    4 +
 config/locales/cs.yml                              |    4 +
 config/locales/da.yml                              |    4 +
 config/locales/de.yml                              |    4 +
 config/locales/el.yml                              |    4 +
 config/locales/en.yml                              |    6 ++-
 config/locales/es.yml                              |    4 +
 config/locales/fi.yml                              |    4 +
 config/locales/fr.yml                              |    4 +
 config/locales/gl.yml                              |    4 +
 config/locales/he.yml                              |    4 +
 config/locales/hu.yml                              |    4 +
 config/locales/it.yml                              |    4 +
 config/locales/ja.yml                              |    4 +
 config/locales/ko.yml                              |    4 +
 config/locales/lt.yml                              |    4 +
 config/locales/nl.yml                              |    4 +
 config/locales/no.yml                              |    4 +
 config/locales/pl.yml                              |    4 +
 config/locales/pt-BR.yml                           |    4 +
 config/locales/pt.yml                              |    4 +
 config/locales/ro.yml                              |    4 +
 config/locales/ru.yml                              |    4 +
 config/locales/sk.yml                              |    4 +
 config/locales/sl.yml                              |    4 +
 config/locales/sr.yml                              |    4 +
 config/locales/sv.yml                              |    4 +
 config/locales/th.yml                              |    4 +
 config/locales/tr.yml                              |    4 +
 config/locales/uk.yml                              |    4 +
 config/locales/vi.yml                              |    4 +
 config/locales/zh-TW.yml                           |    4 +
 config/locales/zh.yml                              |    4 +
 config/settings.yml                                |    2 +
 ...12029_add_default_done_ratio_to_issue_status.rb |    9 +++
 public/images/table_multiple.png                   |  Bin 0 -> 612 bytes
 public/stylesheets/application.css                 |    1 +
 test/functional/issue_statuses_controller_test.rb  |   23 ++++++++
 test/unit/issue_status_test.rb                     |   34 +++++++++++
 test/unit/issue_test.rb                            |   60 ++++++++++++++++++++
 52 files changed, 335 insertions(+), 4 deletions(-)
 create mode 100644 db/migrate/20091123212029_add_default_done_ratio_to_issue_status.rb
 create mode 100644 public/images/table_multiple.png

diff --git a/app/controllers/issue_statuses_controller.rb b/app/controllers/issue_statuses_controller.rb
index bee7f48..3be6abf 100644
--- a/app/controllers/issue_statuses_controller.rb
+++ b/app/controllers/issue_statuses_controller.rb
@@ -18,7 +18,7 @@
 class IssueStatusesController < ApplicationController
   before_filter :require_admin
 
-  verify :method => :post, :only => [ :destroy, :create, :update, :move ],
+  verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ],
          :redirect_to => { :action => :list }
          
   def index
@@ -66,4 +66,13 @@ class IssueStatusesController < ApplicationController
     flash[:error] = "Unable to delete issue status"
     redirect_to :action => 'list'
   end  	
+  
+  def update_issue_done_ratio
+    if IssueStatus.update_issue_done_ratios
+      flash[:notice] = l(:notice_issue_done_ratios_updated)
+    else
+      flash[:error] =  l(:error_issue_done_ratios_not_updated)
+    end
+    redirect_to :action => 'list'
+  end
 end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index cfc2a1b..7f75bcc 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -55,7 +55,8 @@ class Issue < ActiveRecord::Base
                                           :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
   
   named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
-  
+
+  before_save :update_done_ratio_from_issue_status
   after_save :create_journal
   
   # Returns true if usr or current user is allowed to view the issue
@@ -132,6 +133,14 @@ class Issue < ActiveRecord::Base
     write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
   end
   
+  def done_ratio
+    if Setting.issue_status_for_done_ratio? && !self.status.default_done_ratio.blank?
+      self.status.default_done_ratio
+    else
+      read_attribute(:done_ratio)
+    end
+  end
+  
   def validate
     if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
       errors.add :due_date, :not_a_date
@@ -165,6 +174,14 @@ class Issue < ActiveRecord::Base
     end
   end
   
+  # Set the done_ratio using the status if that setting is set.  This will keep the done_ratios
+  # even if the user turns off the setting later
+  def update_done_ratio_from_issue_status
+    if Setting.issue_status_for_done_ratio? && !self.status.default_done_ratio.blank?
+      self.done_ratio = self.status.default_done_ratio
+    end
+  end
+  
   def after_save
     # Reload is needed in order to get the right status
     reload
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb
index ca33d37..b8c93a1 100644
--- a/app/models/issue_status.rb
+++ b/app/models/issue_status.rb
@@ -33,6 +33,18 @@ class IssueStatus < ActiveRecord::Base
   def self.default
     find(:first, :conditions =>["is_default=?", true])
   end
+  
+  # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
+  def self.update_issue_done_ratios
+    if Setting.issue_status_for_done_ratio?
+      IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status|
+        Issue.update_all(["done_ratio = ?", status.default_done_ratio],
+                         ["status_id = ?", status.id])
+      end
+    end
+
+    return Setting.issue_status_for_done_ratio?
+  end
 
   # Returns an array of all statuses the given role can switch to
   # Uses association cache when called more than one time
diff --git a/app/views/issue_statuses/_form.rhtml b/app/views/issue_statuses/_form.rhtml
index b6a5bc1..bb638ca 100644
--- a/app/views/issue_statuses/_form.rhtml
+++ b/app/views/issue_statuses/_form.rhtml
@@ -5,6 +5,11 @@
 <p><label for="issue_status_name"><%=l(:field_name)%><span class="required"> *</span></label>
 <%= text_field 'issue_status', 'name'  %></p>
 
+<% if Setting.issue_status_for_done_ratio? %>
+<p><label for="issue_done_ratio"><%=l(:field_done_ratio)%></label>
+<%= select 'issue_status', :default_done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
+<% end %>
+
 <p><label for="issue_status_is_closed"><%=l(:field_is_closed)%></label>
 <%= check_box 'issue_status', 'is_closed' %></p>
 
diff --git a/app/views/issue_statuses/list.rhtml b/app/views/issue_statuses/list.rhtml
index ca97315..0eb7fc0 100644
--- a/app/views/issue_statuses/list.rhtml
+++ b/app/views/issue_statuses/list.rhtml
@@ -1,5 +1,6 @@
 <div class="contextual">
 <%= link_to l(:label_issue_status_new), {:action => 'new'}, :class => 'icon icon-add' %>
+<%= link_to(l(:label_update_issue_done_ratios), {:action => 'update_issue_done_ratio'}, :class => 'icon icon-multiple', :method => 'post', :confirm => l(:text_are_you_sure)) if Setting.issue_status_for_done_ratio? %>
 </div>
 
 <h2><%=l(:label_issue_status_plural)%></h2>
@@ -7,6 +8,9 @@
 <table class="list">
   <thead><tr>
   <th><%=l(:field_status)%></th>
+  <% if Setting.issue_status_for_done_ratio? %>
+  <th><%=l(:field_done_ratio)%></th>
+  <% end %>
   <th><%=l(:field_is_default)%></th>
   <th><%=l(:field_is_closed)%></th>
   <th><%=l(:button_sort)%></th>
@@ -16,6 +20,9 @@
 <% for status in @issue_statuses %>
   <tr class="<%= cycle("odd", "even") %>">
   <td><%= link_to status.name, :action => 'edit', :id => status %></td>
+  <% if Setting.issue_status_for_done_ratio? %>
+  <td align="center"><%= h status.default_done_ratio %></td>
+  <% end %>
   <td align="center"><%= image_tag 'true.png' if status.is_default? %></td>
   <td align="center"><%= image_tag 'true.png' if status.is_closed? %></td>
   <td align="center" style="width:15%;"><%= reorder_links('issue_status', {:action => 'update', :id => status}) %></td>
diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml
index c61c79d..9606903 100644
--- a/app/views/issues/_form.rhtml
+++ b/app/views/issues/_form.rhtml
@@ -41,7 +41,9 @@
 <p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %></p>
 <p><%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %></p>
 <p><%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %></p>
+<% unless Setting.issue_status_for_done_ratio? %>
 <p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
+<% end %>
 </div>
 
 <div style="clear:both;"> </div>
diff --git a/app/views/issues/_form_update.rhtml b/app/views/issues/_form_update.rhtml
index 5304ee2..4634b8b 100644
--- a/app/views/issues/_form_update.rhtml
+++ b/app/views/issues/_form_update.rhtml
@@ -4,7 +4,9 @@
 <p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p>
 </div>
 <div class="splitcontentright">
+<% unless Setting.issue_status_for_done_ratio? %>
 <p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
+<% end %>
 <% unless @issue.assignable_versions.empty? %>
 <p><%= f.select :fixed_version_id, (@issue.assignable_versions.collect {|v| [v.name, v.id]}), :include_blank => true %></p>
 <% end %>
diff --git a/app/views/issues/bulk_edit.rhtml b/app/views/issues/bulk_edit.rhtml
index 10a5bb5..f333816 100644
--- a/app/views/issues/bulk_edit.rhtml
+++ b/app/views/issues/bulk_edit.rhtml
@@ -35,8 +35,10 @@
 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %></label>
 <label><%= l(:field_due_date) %>: 
 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %></label>
+<% unless Setting.issue_status_for_done_ratio? %>
 <label><%= l(:field_done_ratio) %>: 
 <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
+<% end %>
 </p>
 
 <% @custom_fields.each do |custom_field| %>
diff --git a/app/views/issues/context_menu.rhtml b/app/views/issues/context_menu.rhtml
index 073f12b..cd88402 100644
--- a/app/views/issues/context_menu.rhtml
+++ b/app/views/issues/context_menu.rhtml
@@ -66,6 +66,7 @@
 		</ul>
 	</li>
 	<% end -%>
+  <% unless Setting.issue_status_for_done_ratio? %>
 	<li class="folder">
 		<a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
 		<ul>
@@ -75,7 +76,7 @@
 		<% end -%>
 		</ul>
 	</li>
-	
+  <% end %>
 <% if !@issue.nil? %>
 	<li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
 	        :class => 'icon-copy', :disabled => !@can[:copy] %></li>
diff --git a/app/views/settings/_issues.rhtml b/app/views/settings/_issues.rhtml
index b0277fa..f60afb4 100644
--- a/app/views/settings/_issues.rhtml
+++ b/app/views/settings/_issues.rhtml
@@ -11,6 +11,11 @@
 <%= check_box_tag 'settings[display_subprojects_issues]', 1, Setting.display_subprojects_issues? %>
 </p>
 
+<p><label><%= l(:setting_use_issue_status_for_done_ratio) %></label>
+<%= hidden_field_tag 'settings[issue_status_for_done_ratio]', 0 %>
+<%= check_box_tag 'settings[issue_status_for_done_ratio]', 1, Setting.issue_status_for_done_ratio? %>
+</p>
+
 <p><label><%= l(:setting_issues_export_limit) %></label>
 <%= text_field_tag 'settings[issues_export_limit]', Setting.issues_export_limit, :size => 6 %></p>
 </div>
diff --git a/config/locales/bg.yml b/config/locales/bg.yml
index e091f85..54c5b95 100644
--- a/config/locales/bg.yml
+++ b/config/locales/bg.yml
@@ -835,3 +835,7 @@ bg:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/bs.yml b/config/locales/bs.yml
index d6b1590..4aaeba7 100644
--- a/config/locales/bs.yml
+++ b/config/locales/bs.yml
@@ -859,3 +859,7 @@ bs:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/ca.yml b/config/locales/ca.yml
index 6aacce6..1d180f5 100644
--- a/config/locales/ca.yml
+++ b/config/locales/ca.yml
@@ -838,3 +838,7 @@ ca:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/cs.yml b/config/locales/cs.yml
index 943fb69..dcb31db 100644
--- a/config/locales/cs.yml
+++ b/config/locales/cs.yml
@@ -841,3 +841,7 @@ cs:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/da.yml b/config/locales/da.yml
index 33acc45..64628ba 100644
--- a/config/locales/da.yml
+++ b/config/locales/da.yml
@@ -861,3 +861,7 @@ da:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 29273f3..4fae09f 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -861,3 +861,7 @@ de:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/el.yml b/config/locales/el.yml
index 6907603..bd8ad53 100644
--- a/config/locales/el.yml
+++ b/config/locales/el.yml
@@ -841,3 +841,7 @@ el:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 85234cb..911e128 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -147,6 +147,7 @@ en:
   notice_account_pending: "Your account was created and is now pending administrator approval."
   notice_default_data_loaded: Default configuration successfully loaded.
   notice_unable_delete_version: Unable to delete version.
+  notice_issue_done_ratios_updated: Issue done ratios updated.
   
   error_can_t_load_default_data: "Default configuration could not be loaded: {{value}}"
   error_scm_not_found: "The entry or revision was not found in the repository."
@@ -156,7 +157,8 @@ en:
   error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.'
   error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
   error_can_not_reopen_issue_on_closed_version: 'An issue assigned to a closed version can not be reopened'
-  
+  error_issue_done_ratios_not_updated: "Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'"
+
   warning_attachments_not_saved: "{{count}} file(s) could not be saved."
   
   mail_subject_lost_password: "Your {{value}} password"
@@ -307,6 +309,7 @@ en:
   setting_sequential_project_identifiers: Generate sequential project identifiers
   setting_gravatar_enabled: Use Gravatar user icons
   setting_gravatar_default: Default Gravatar image
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
   setting_diff_max_lines_displayed: Max number of diff lines displayed
   setting_file_max_size_displayed: Max size of text files displayed inline
   setting_repository_log_display_limit: Maximum number of revisions displayed on file log
@@ -709,6 +712,7 @@ en:
   label_group_plural: Groups
   label_group_new: New group
   label_time_entry_plural: Spent time
+  label_update_issue_done_ratios: Update issue done ratios
   
   button_login: Login
   button_submit: Submit
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 07bb880..cd47648 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -882,3 +882,7 @@ es:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/fi.yml b/config/locales/fi.yml
index 4501e63..176d2ce 100644
--- a/config/locales/fi.yml
+++ b/config/locales/fi.yml
@@ -871,3 +871,7 @@ fi:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 2e2a69b..fe5ac8f 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -864,3 +864,7 @@ fr:
   field_active: Actif
   enumeration_system_activity: Activité système
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/gl.yml b/config/locales/gl.yml
index f2af3ed..685aba9 100644
--- a/config/locales/gl.yml
+++ b/config/locales/gl.yml
@@ -861,3 +861,7 @@ gl:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/he.yml b/config/locales/he.yml
index cae31b3..4b6f95a 100644
--- a/config/locales/he.yml
+++ b/config/locales/he.yml
@@ -845,3 +845,7 @@ he:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/hu.yml b/config/locales/hu.yml
index ef37ef2..4eff53f 100644
--- a/config/locales/hu.yml
+++ b/config/locales/hu.yml
@@ -866,3 +866,7 @@
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 9460211..53dcde5 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -848,3 +848,7 @@ it:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/ja.yml b/config/locales/ja.yml
index 450cff9..dd2101f 100644
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -870,3 +870,7 @@ ja:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/ko.yml b/config/locales/ko.yml
index 260d353..779283b 100644
--- a/config/locales/ko.yml
+++ b/config/locales/ko.yml
@@ -901,3 +901,7 @@ ko:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/lt.yml b/config/locales/lt.yml
index 5d4ff19..c58980d 100644
--- a/config/locales/lt.yml
+++ b/config/locales/lt.yml
@@ -871,3 +871,7 @@ lt:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/nl.yml b/config/locales/nl.yml
index f41e42b..c565969 100644
--- a/config/locales/nl.yml
+++ b/config/locales/nl.yml
@@ -823,3 +823,7 @@ nl:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/no.yml b/config/locales/no.yml
index d9f81cf..178492f 100644
--- a/config/locales/no.yml
+++ b/config/locales/no.yml
@@ -836,3 +836,7 @@
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/pl.yml b/config/locales/pl.yml
index 6227892..f407055 100644
--- a/config/locales/pl.yml
+++ b/config/locales/pl.yml
@@ -864,3 +864,7 @@ pl:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml
index 2019c49..5382371 100644
--- a/config/locales/pt-BR.yml
+++ b/config/locales/pt-BR.yml
@@ -867,3 +867,7 @@ pt-BR:
   button_move_and_follow: Mover e seguir
   setting_default_projects_modules: Módulos habilitados por padrão para novos projetos
   setting_gravatar_default: Imagem Gravatar padrão
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/pt.yml b/config/locales/pt.yml
index 3b3f104..c8fa09a 100644
--- a/config/locales/pt.yml
+++ b/config/locales/pt.yml
@@ -853,3 +853,7 @@ pt:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/ro.yml b/config/locales/ro.yml
index 19e5a5c..3d27ecb 100644
--- a/config/locales/ro.yml
+++ b/config/locales/ro.yml
@@ -838,3 +838,7 @@ ro:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/ru.yml b/config/locales/ru.yml
index 7555af4..355418e 100644
--- a/config/locales/ru.yml
+++ b/config/locales/ru.yml
@@ -949,3 +949,7 @@ ru:
   button_move_and_follow: Переместить и перейти
   setting_default_projects_modules: Включенные по умолчанию модули для новых проектов
   setting_gravatar_default: Изображение Gravatar по умолчанию
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/sk.yml b/config/locales/sk.yml
index af8eab1..2dbfba9 100644
--- a/config/locales/sk.yml
+++ b/config/locales/sk.yml
@@ -840,3 +840,7 @@ sk:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/sl.yml b/config/locales/sl.yml
index 56cd421..ddad6da 100644
--- a/config/locales/sl.yml
+++ b/config/locales/sl.yml
@@ -837,3 +837,7 @@ sl:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/sr.yml b/config/locales/sr.yml
index 3227463..90143d0 100644
--- a/config/locales/sr.yml
+++ b/config/locales/sr.yml
@@ -856,3 +856,7 @@
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/sv.yml b/config/locales/sv.yml
index a4698fc..f62a701 100644
--- a/config/locales/sv.yml
+++ b/config/locales/sv.yml
@@ -889,3 +889,7 @@ sv:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/th.yml b/config/locales/th.yml
index 7b41412..6c71e07 100644
--- a/config/locales/th.yml
+++ b/config/locales/th.yml
@@ -838,3 +838,7 @@ th:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/tr.yml b/config/locales/tr.yml
index a0a1c26..e158aa2 100644
--- a/config/locales/tr.yml
+++ b/config/locales/tr.yml
@@ -868,3 +868,7 @@ tr:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/uk.yml b/config/locales/uk.yml
index 7d8d1a9..88c1a10 100644
--- a/config/locales/uk.yml
+++ b/config/locales/uk.yml
@@ -837,3 +837,7 @@ uk:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/vi.yml b/config/locales/vi.yml
index fef14e4..cf41dde 100644
--- a/config/locales/vi.yml
+++ b/config/locales/vi.yml
@@ -900,3 +900,7 @@ vi:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml
index 7eab6fa..692742b 100644
--- a/config/locales/zh-TW.yml
+++ b/config/locales/zh-TW.yml
@@ -932,3 +932,7 @@
   enumeration_doc_categories: 文件分類
   enumeration_activities: 活動 (時間追蹤)
   enumeration_system_activity: 系統活動
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index a40851b..4a81b69 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -865,3 +865,7 @@ zh:
   button_move_and_follow: Move and follow
   setting_default_projects_modules: Default enabled modules for new projects
   setting_gravatar_default: Default Gravatar image
+  error_issue_done_ratios_not_updated: Issue done ratios not updated.  Please confirm you enabled 'Use issue status for  done ratio'
+  setting_use_issue_status_for_done_ratio: Use issue status for done ratio
+  notice_issue_done_ratios_updated: Issue done ratios updated.
+  label_update_issue_done_ratios: Update issue done ratios
diff --git a/config/settings.yml b/config/settings.yml
index ca0cc3d..1f5e41d 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -129,6 +129,8 @@ issue_list_default_columns:
   - updated_on
 display_subprojects_issues:
   default: 1
+issue_status_for_done_ratio:
+  default: 0
 default_projects_public:
   default: 1
 default_projects_modules:
diff --git a/db/migrate/20091123212029_add_default_done_ratio_to_issue_status.rb b/db/migrate/20091123212029_add_default_done_ratio_to_issue_status.rb
new file mode 100644
index 0000000..f77e3d5
--- /dev/null
+++ b/db/migrate/20091123212029_add_default_done_ratio_to_issue_status.rb
@@ -0,0 +1,9 @@
+class AddDefaultDoneRatioToIssueStatus < ActiveRecord::Migration
+  def self.up
+    add_column :issue_statuses, :default_done_ratio, :integer
+  end
+
+  def self.down
+    remove_column :issue_statuses, :default_one_ratio
+  end
+end
diff --git a/public/images/table_multiple.png b/public/images/table_multiple.png
new file mode 100644
index 0000000000000000000000000000000000000000..d76448e34a04f5c94794597f91ade6f423b3f6cf
GIT binary patch
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 7f5d1b2..13658f1 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -698,6 +698,7 @@ vertical-align: middle;
 .icon-move { background-image: url(../images/move.png); }
 .icon-save { background-image: url(../images/save.png); }
 .icon-cancel { background-image: url(../images/cancel.png); }
+.icon-multiple { background-image: url(../images/table_multiple.png); }
 .icon-folder { background-image: url(../images/folder.png); }
 .open .icon-folder { background-image: url(../images/folder_open.png); }
 .icon-package { background-image: url(../images/package.png); }
diff --git a/test/functional/issue_statuses_controller_test.rb b/test/functional/issue_statuses_controller_test.rb
index 5e012f7..d34a71c 100644
--- a/test/functional/issue_statuses_controller_test.rb
+++ b/test/functional/issue_statuses_controller_test.rb
@@ -70,4 +70,27 @@ class IssueStatusesControllerTest < ActionController::TestCase
     assert_redirected_to 'issue_statuses/list'
     assert_not_nil IssueStatus.find_by_id(1)
   end
+
+  context "on POST to :update_issue_done_ratio" do
+    context "with Setting.issue_status_for_done_ratio off" do
+      setup do
+        Setting.issue_status_for_done_ratio = 0
+        post :update_issue_done_ratio
+      end
+
+      should_set_the_flash_to /not updated/
+      should_redirect_to('the list') { '/issue_statuses/list' }
+    end
+
+    context "with Setting.issue_status_for_done_ratio on" do
+      setup do
+        Setting.issue_status_for_done_ratio = 1
+        post :update_issue_done_ratio
+      end
+
+      should_set_the_flash_to /Issue done ratios updated/
+      should_redirect_to('the list') { '/issue_statuses/list' }
+    end
+  end
+  
 end
diff --git a/test/unit/issue_status_test.rb b/test/unit/issue_status_test.rb
index 042f30e..5835cec 100644
--- a/test/unit/issue_status_test.rb
+++ b/test/unit/issue_status_test.rb
@@ -66,4 +66,38 @@ class IssueStatusTest < ActiveSupport::TestCase
     status.reload
     assert status.is_default?
   end
+
+  context "#update_done_ratios" do
+    setup do
+      @issue = Issue.find(1)
+      @issue_status = IssueStatus.find(1)
+      @issue_status.update_attribute(:default_done_ratio, 50)
+    end
+    
+    context "with Setting.issue_status_for_done_ratio off" do
+      setup do
+        Setting.issue_status_for_done_ratio = 0
+      end
+      
+      should "change nothing" do
+        assert_equal 0, Issue.count(:conditions => {:done_ratio => 50})
+      end
+    end
+
+    context "with Setting.issue_status_for_done_ratio on" do
+      setup do
+        Setting.issue_status_for_done_ratio = 1
+      end
+      
+      should "update all of the issue's done_ratios to match their Issue Status" do
+        IssueStatus.update_issue_done_ratios
+        
+        issues = Issue.find([1,3,4,5,6,7,9,10])
+        issues.each do |issue|
+          assert_equal @issue_status, issue.status
+          assert_equal 50, issue.read_attribute(:done_ratio)
+        end
+      end
+    end
+  end
 end
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 3b0dd26..692f9e8 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -400,4 +400,64 @@ class IssueTest < ActiveSupport::TestCase
     end
     assert ActionMailer::Base.deliveries.empty?
   end
+
+  context "#done_ratio" do
+    setup do
+      @issue = Issue.find(1)
+      @issue_status = IssueStatus.find(1)
+      @issue_status.update_attribute(:default_done_ratio, 50)
+    end
+    
+    context "with Setting.issue_status_for_done_ratio off" do
+      setup do
+        Setting.issue_status_for_done_ratio = 0
+      end
+      
+      should "read the issue's field" do
+        assert_equal 0, @issue.done_ratio
+      end
+    end
+
+    context "with Setting.issue_status_for_done_ratio on" do
+      setup do
+        Setting.issue_status_for_done_ratio = 1
+      end
+      
+      should "read the Issue Status's default done ratio" do
+        assert_equal 50, @issue.done_ratio
+      end
+    end
+  end
+
+  context "#update_done_ratio_from_issue_status" do
+    setup do
+      @issue = Issue.find(1)
+      @issue_status = IssueStatus.find(1)
+      @issue_status.update_attribute(:default_done_ratio, 50)
+    end
+    
+    context "with Setting.issue_status_for_done_ratio off" do
+      setup do
+        Setting.issue_status_for_done_ratio = 0
+      end
+      
+      should "not change the issue" do
+        @issue.update_done_ratio_from_issue_status
+
+        assert_equal 0, @issue.done_ratio
+      end
+    end
+
+    context "with Setting.issue_status_for_done_ratio on" do
+      setup do
+        Setting.issue_status_for_done_ratio = 1
+      end
+      
+      should "not change the issue's done ratio" do
+        @issue.update_done_ratio_from_issue_status
+
+        assert_equal 50, @issue.done_ratio
+      end
+    end
+  end
 end
-- 
1.6.5

