Add by_budget scope to Investment and use it

This commit is contained in:
Bertocq
2018-02-10 16:36:14 +01:00
parent bd10285431
commit 2341a2f70b
3 changed files with 4 additions and 3 deletions

View File

@@ -101,7 +101,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end
def load_investment
@investment = Budget::Investment.where(budget_id: @budget.id).find(params[:id])
@investment = Budget::Investment.by_budget(@budget).find(params[:id])
end
def load_admins

View File

@@ -57,7 +57,7 @@ module BudgetsHelper
end
def investment_tags_select_options(budget)
Budget::Investment.where(budget_id: budget).tags_on(:valuation).order(:name).select(:name).distinct
Budget::Investment.by_budget(budget).tags_on(:valuation).order(:name).select(:name).distinct
end
def budget_published?(budget)

View File

@@ -81,6 +81,7 @@ class Budget
scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) }
scope :by_tag, ->(tag_name) { tagged_with(tag_name) }
scope :by_valuator, ->(valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) }
scope :by_budget, ->(budget) { where(budget: budget) }
scope :for_render, -> { includes(:heading) }
@@ -103,7 +104,7 @@ class Budget
def self.scoped_filter(params, current_filter)
budget = Budget.find_by(id: params[:budget_id]) || Budget.find_by(slug: params[:budget_id])
results = Investment.where(budget_id: budget.id)
results = Investment.by_budget(budget)
results = limit_results(budget, params, results) if params[:max_per_heading].present?
results = results.where(group_id: params[:group_id]) if params[:group_id].present?