Project

General

Profile

Patch #37862 » 0001-Move-logic-for-estimated-remaining-hours-from-QueryC.patch

Marius BĂLTEANU, 2024-05-02 18:15

View differences:

app/models/issue.rb
1165 1165
    end
1166 1166
  end
1167 1167

  
1168
  # Returns the number of estimated remaining hours on this issue
1169
  def estimated_remaining_hours
1170
    (estimated_hours || 0) * (100 - (done_ratio || 0)) / 100
1171
  end
1172

  
1168 1173
  def relations
1169 1174
    @relations ||= IssueRelation::Relations.new(
1170 1175
      self,
app/models/issue_query.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
class IssueQuery < Query
21
  class EstimatedRemainingHoursColumn < QueryColumn
22
    COLUMN_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
23

  
24
    def initialize
25
      super(:estimated_remaining_hours, totalable: true, sortable: COLUMN_SQL)
26
    end
27

  
28
    def value(object)
29
      (object.estimated_hours || 0) * (100 - (object.done_ratio || 0)) / 100
30
    end
31

  
32
    def value_object(object)
33
      value(object)
34
    end
35
  end
36

  
37 21
  self.queried_class = Issue
38 22
  self.view_permission = :view_issues
39 23

  
24
  ESTIMATED_REMAINING_HOURS_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
40 25
  self.available_columns = [
41 26
    QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id",
42 27
                    :default_order => 'desc', :caption => '#', :frozen => true),
......
66 51
    QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
67 52
    QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
68 53
                    :totalable => true),
69
    EstimatedRemainingHoursColumn.new,
54
    QueryColumn.new(:estimated_remaining_hours,
55
                    :sortable => ESTIMATED_REMAINING_HOURS_SQL,
56
                    :totalable => true),
70 57
    QueryColumn.new(
71 58
      :total_estimated_hours,
72 59
      :sortable =>
......
390 377
  end
391 378

  
392 379
  def total_for_estimated_remaining_hours(scope)
393
    map_total(scope.sum(EstimatedRemainingHoursColumn::COLUMN_SQL)) {|t| t.to_f.round(2)}
380
    map_total(scope.sum(ESTIMATED_REMAINING_HOURS_SQL)) {|t| t.to_f.round(2)}
394 381
  end
395 382

  
396 383
  # Returns sum of all the issue's time entries hours
(3-3/5)