Project

General

Profile

Feature #5490 » issue_no_parent_updates-2.2-stable.diff

Avoid parent ticket updates of priority, start & due date, estimated time and make fields editable again - Erny Revilla, 2013-01-17 15:55

View differences:

app/models/issue.rb
1201 1201
  def recalculate_attributes_for(issue_id)
1202 1202
    if issue_id && p = Issue.find_by_id(issue_id)
1203 1203
      # priority = highest priority of children
1204
      if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :joins => :priority)
1205
        p.priority = IssuePriority.find_by_position(priority_position)
1206
      end
1204
      #Disabled
1205
      #if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :joins => :priority)
1206
      #  p.priority = IssuePriority.find_by_position(priority_position)
1207
      #end
1207 1208

  
1208 1209
      # start/due dates = lowest/highest dates of children
1209
      p.start_date = p.children.minimum(:start_date)
1210
      p.due_date = p.children.maximum(:due_date)
1211
      if p.start_date && p.due_date && p.due_date < p.start_date
1212
        p.start_date, p.due_date = p.due_date, p.start_date
1213
      end
1210
      #p.start_date = p.children.minimum(:start_date)
1211
      #p.due_date = p.children.maximum(:due_date)
1212
      #if p.start_date && p.due_date && p.due_date < p.start_date
1213
      #  p.start_date, p.due_date = p.due_date, p.start_date
1214
      #end
1214 1215

  
1215 1216
      # done ratio = weighted average ratio of leaves
1216
      unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
1217
        leaves_count = p.leaves.count
1218
        if leaves_count > 0
1219
          average = p.leaves.average(:estimated_hours).to_f
1220
          if average == 0
1221
            average = 1
1222
          end
1223
          done = p.leaves.sum("COALESCE(estimated_hours, #{average}) * (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f
1224
          progress = done / (average * leaves_count)
1225
          p.done_ratio = progress.round
1226
        end
1227
      end
1217
      #Disabled
1218
      #unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
1219
      #  leaves_count = p.leaves.count
1220
      #  if leaves_count > 0
1221
      #    average = p.leaves.average(:estimated_hours).to_f
1222
      #    if average == 0
1223
      #      average = 1
1224
      #    end
1225
      #    done = p.leaves.sum("COALESCE(estimated_hours, #{average}) * (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f
1226
      #    progress = done / (average * leaves_count)
1227
      #    p.done_ratio = progress.round
1228
      #  end
1229
      #end
1228 1230

  
1229 1231
      # estimate = sum of leaves estimates
1230
      p.estimated_hours = p.leaves.sum(:estimated_hours).to_f
1231
      p.estimated_hours = nil if p.estimated_hours == 0.0
1232
      #Disabled
1233
      #p.estimated_hours = p.leaves.sum(:estimated_hours).to_f
1234
      #p.estimated_hours = nil if p.estimated_hours == 0.0
1232 1235

  
1233 1236
      # ancestors will be recursively updated
1234 1237
      p.save(:validate => false)
app/views/issues/_attributes.html.erb
11 11
<% end %>
12 12

  
13 13
<% if @issue.safe_attribute? 'priority_id' %>
14
<p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => !@issue.leaf? %></p>
14
<p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => false %></p>
15 15
<% end %>
16 16

  
17 17
<% if @issue.safe_attribute? 'assigned_to_id' %>
......
47 47
<% end %>
48 48

  
49 49
<% if @issue.safe_attribute? 'start_date' %>
50
<p><%= f.text_field :start_date, :size => 10, :disabled => !@issue.leaf?, :required => @issue.required_attribute?('start_date') %><%= calendar_for('issue_start_date') if @issue.leaf? %></p>
50
<p><%= f.text_field :start_date, :size => 10, :disabled => false, :required => @issue.required_attribute?('start_date') %><%= calendar_for('issue_start_date') %></p>
51 51
<% end %>
52 52

  
53 53
<% if @issue.safe_attribute? 'due_date' %>
54
<p><%= f.text_field :due_date, :size => 10, :disabled => !@issue.leaf?, :required => @issue.required_attribute?('due_date') %><%= calendar_for('issue_due_date') if @issue.leaf? %></p>
54
<p><%= f.text_field :due_date, :size => 10, :disabled => false, :required => @issue.required_attribute?('due_date') %><%= calendar_for('issue_due_date') %></p>
55 55
<% end %>
56 56

  
57 57
<% if @issue.safe_attribute? 'estimated_hours' %>
58
<p><%= f.text_field :estimated_hours, :size => 3, :disabled => !@issue.leaf?, :required => @issue.required_attribute?('estimated_hours') %> <%= l(:field_hours) %></p>
58
<p><%= f.text_field :estimated_hours, :size => 3, :disabled => false, :required => @issue.required_attribute?('estimated_hours') %> <%= l(:field_hours) %></p>
59 59
<% end %>
60 60

  
61
<% if @issue.safe_attribute?('done_ratio') && @issue.leaf? && Issue.use_field_for_done_ratio? %>
61
<% if @issue.safe_attribute?('done_ratio') && Issue.use_field_for_done_ratio? %>
62 62
<p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }), :required => @issue.required_attribute?('done_ratio') %></p>
63 63
<% end %>
64 64
</div>
(3-3/9)