Show valuator group investments to their valuators

When accessing the valuation area, we were only displaying the
investments directly assigned to the current valuator, but we weren't
displaying the investments assigned to that valuator's group.

Using the `assigned_investments_ids` method, which takes the valuator
group into account, solves the issue.

We've also found an issue on our development machines: since we don't
have a unique index per `investment_id` and `valuator_id` in the
`budget_valuator_assignments` table, we've found duplicate records on
this table. When that happened, we were displaying the same investment
several times.

Since now we no longer join this table in the query returning the
investment, this issue is also solved, and we're adding a test for it.
We can now remove the call to the `distinct` method when calculating the
number of investments per heading.
This commit is contained in:
Javi Martín
2023-02-09 20:56:45 +01:00
parent f7dfe30675
commit 45b9eccfd8
4 changed files with 71 additions and 2 deletions

View File

@@ -73,7 +73,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
end
def heading_filters
investments = @budget.investments.visible_to_valuator(current_user.valuator).distinct
investments = @budget.investments.visible_to_valuator(current_user.valuator)
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id)).sort_by(&:name)
all_headings_filter = [