Fix Valuation Investment index heading filters
Why: Heading filter where not being correctly displayed How: Increasing scenario to cover all possible combinations, and fixing the heading_filters method of the Valuation Budget Investment Controller to correctly: * Find how many investments the valuator can access * Count investments for each heading
This commit is contained in:
@@ -73,19 +73,25 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
end
|
||||
|
||||
def heading_filters
|
||||
investments = @budget.investments.by_valuator(current_user.valuator.try(:id))
|
||||
.valuation_open.select(:heading_id).all.to_a
|
||||
investments = @budget.investments.by_valuator(current_user.valuator.try(:id)).distinct
|
||||
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id).uniq)
|
||||
.order(name: :asc)
|
||||
|
||||
[ { name: t('valuation.budget_investments.index.headings_filter_all'),
|
||||
id: nil,
|
||||
pending_count: investments.size
|
||||
}
|
||||
] + Budget::Heading.where(id: investments.map(&:heading_id).uniq).order(name: :asc).collect do |h|
|
||||
{ name: h.name,
|
||||
id: h.id,
|
||||
pending_count: investments.count{|x| x.heading_id == h.id}
|
||||
}
|
||||
end
|
||||
all_headings_filter = [
|
||||
{
|
||||
name: t('valuation.budget_investments.index.headings_filter_all'),
|
||||
id: nil,
|
||||
count: investments.size
|
||||
}
|
||||
]
|
||||
|
||||
filters = investment_headings.inject(all_headings_filter) do |filters, heading|
|
||||
filters << {
|
||||
name: heading.name,
|
||||
id: heading.id,
|
||||
count: investments.select{|i| i.heading_id == heading.id}.size
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def params_for_current_valuator
|
||||
|
||||
Reference in New Issue
Block a user