Extract method to filter investments by status
This commit is contained in:
@@ -14,8 +14,7 @@ module Budgets
|
||||
def investments_by_heading
|
||||
if params[:status].present?
|
||||
@budget.investments.winners
|
||||
.joins(:milestones).includes(:milestones)
|
||||
.select { |i| i.milestone_status_id == params[:status].to_i }
|
||||
.with_milestone_status_id(params[:status])
|
||||
.uniq
|
||||
.group_by(&:heading)
|
||||
else
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
module BudgetExecutionsHelper
|
||||
|
||||
def filters_select_counts(status)
|
||||
@budget.investments.winners.with_milestones.select do |investment|
|
||||
investment.milestone_status_id == status
|
||||
end.count
|
||||
@budget.investments.winners.with_milestone_status_id(status).count
|
||||
end
|
||||
|
||||
def first_milestone_with_image(investment)
|
||||
|
||||
@@ -342,6 +342,12 @@ class Budget
|
||||
self.valuator_groups.collect(&:name).compact.join(', ').presence
|
||||
end
|
||||
|
||||
def self.with_milestone_status_id(status_id)
|
||||
joins(:milestones).includes(:milestones).select do |investment|
|
||||
investment.milestone_status_id == status_id.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def milestone_status_id
|
||||
milestones.published.with_status.order_by_publication_date.last&.status_id
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user