1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-01 03:57:15 +00:00

Move logic for estimated remaining hours from @QueryColumn@ to @Issue@ (#37862).

git-svn-id: https://svn.redmine.org/redmine/trunk@22857 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu 2024-06-04 20:16:08 +00:00
parent 7710d005f2
commit d9ca32b9d1
2 changed files with 10 additions and 18 deletions

View File

@ -1165,6 +1165,11 @@ class Issue < ApplicationRecord
end
end
# Returns the number of estimated remaining hours on this issue
def estimated_remaining_hours
(estimated_hours || 0) * (100 - (done_ratio || 0)) / 100
end
def relations
@relations ||= IssueRelation::Relations.new(
self,

View File

@ -18,25 +18,10 @@
# 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
ESTIMATED_REMAINING_HOURS_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
self.available_columns = [
QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id",
:default_order => 'desc', :caption => '#', :frozen => true),
@ -66,7 +51,9 @@ 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(:estimated_remaining_hours,
:sortable => ESTIMATED_REMAINING_HOURS_SQL,
:totalable => true),
QueryColumn.new(
:total_estimated_hours,
:sortable =>
@ -390,7 +377,7 @@ class IssueQuery < Query
end
def total_for_estimated_remaining_hours(scope)
map_total(scope.sum(EstimatedRemainingHoursColumn::COLUMN_SQL)) {|t| t.to_f.round(2)}
map_total(scope.sum(ESTIMATED_REMAINING_HOURS_SQL)) {|t| t.to_f.round(2)}
end
# Returns sum of all the issue's time entries hours