summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2024-05-01 07:49:29 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2024-05-01 07:49:29 +0000
commit6fa12a95abaff2e5422588a69b8abf4f2ba28d74 (patch)
treef71618b87f919b961b0857a23851accd0c609eb1 /app/models
parent61c7d539dccc3bec3da4d365443fb780bffd8ef0 (diff)
downloadredmine-6fa12a95abaff2e5422588a69b8abf4f2ba28d74.tar.gz
redmine-6fa12a95abaff2e5422588a69b8abf4f2ba28d74.zip
Adds estimated remaining hours issue query column calculated based on estimated time and done ratio (#37862).
Patch by Jens Krämer (@jkraemer). git-svn-id: https://svn.redmine.org/redmine/trunk@22800 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/issue_query.rb25
1 files changed, 24 insertions, 1 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 91678874e..6a2771343 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -18,6 +18,22 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueQuery < Query
+ class EstimatedRemainingHoursColumn < QueryColumn
+ COLUMN_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
+
+ def initialize
+ super :estimated_remaining_hours, totalable: true, sortable: COLUMN_SQL
+ end
+
+ def value(object)
+ (object.estimated_hours || 0) * (100 - (object.done_ratio || 0)) / 100
+ end
+
+ def value_object(object)
+ value(object)
+ end
+ end
+
self.queried_class = Issue
self.view_permission = :view_issues
@@ -50,6 +66,7 @@ class IssueQuery < Query
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
:totalable => true),
+ EstimatedRemainingHoursColumn.new,
QueryColumn.new(
:total_estimated_hours,
:sortable =>
@@ -330,7 +347,9 @@ class IssueQuery < Query
end
disabled_fields = Tracker.disabled_core_fields(trackers).map {|field| field.delete_suffix('_id')}
- disabled_fields << "total_estimated_hours" if disabled_fields.include?("estimated_hours")
+ if disabled_fields.include?("estimated_hours")
+ disabled_fields += %w[total_estimated_hours estimated_remaining_hours]
+ end
@available_columns.reject! do |column|
disabled_fields.include?(column.name.to_s)
end
@@ -370,6 +389,10 @@ class IssueQuery < Query
map_total(scope.sum(:estimated_hours)) {|t| t.to_f.round(2)}
end
+ def total_for_estimated_remaining_hours(scope)
+ map_total(scope.sum(EstimatedRemainingHoursColumn::COLUMN_SQL)) {|t| t.to_f.round(2)}
+ end
+
# Returns sum of all the issue's time entries hours
def total_for_spent_hours(scope)
total = scope.joins(:time_entries).