Add calculate_winners on Admin Budget controller, route and ability for admins

This commit is contained in:
Bertocq
2017-06-21 19:39:28 +02:00
parent ee9d3cd7e3
commit 154cdac332
5 changed files with 21 additions and 9 deletions

View File

@@ -14,10 +14,15 @@ class Admin::BudgetsController < Admin::BaseController
@budget = Budget.includes(groups: :headings).find(params[:id]) @budget = Budget.includes(groups: :headings).find(params[:id])
end end
def new def new; end
end
def edit def edit; end
def calculate_winners
return unless @budget.balloting_process?
@budget.headings.each { |heading| Budget::Result.new(@budget, heading).calculate_winners }
redirect_to admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'winners'),
notice: I18n.t("admin.budgets.winners.calculated")
end end
def update def update

View File

@@ -44,7 +44,7 @@ module Abilities
can [:read, :update, :valuate, :destroy, :summary], SpendingProposal can [:read, :update, :valuate, :destroy, :summary], SpendingProposal
can [:index, :read, :new, :create, :update, :destroy], Budget can [:index, :read, :new, :create, :update, :destroy, :calculate_winners], Budget
can [:read, :create, :update, :destroy], Budget::Group can [:read, :create, :update, :destroy], Budget::Group
can [:read, :create, :update, :destroy], Budget::Heading can [:read, :create, :update, :destroy], Budget::Heading
can [:hide, :update, :toggle_selection], Budget::Investment can [:hide, :update, :toggle_selection], Budget::Investment

View File

@@ -67,8 +67,12 @@ class Budget < ActiveRecord::Base
phase == "finished" phase == "finished"
end end
def balloting_process?
balloting? || reviewing_ballots?
end
def balloting_or_later? def balloting_or_later?
balloting? || reviewing_ballots? || finished? balloting_process? || finished?
end end
def on_hold? def on_hold?

View File

@@ -12,11 +12,10 @@ class Budget
reset_winners reset_winners
investments.each do |investment| investments.each do |investment|
@current_investment = investment @current_investment = investment
if inside_budget? set_winner if inside_budget?
set_winner
end
end end
end end
handle_asynchronously :calculate_winners
def investments def investments
heading.investments.selected.sort_by_ballots heading.investments.selected.sort_by_ballots

View File

@@ -193,6 +193,10 @@ Rails.application.routes.draw do
end end
resources :budgets do resources :budgets do
member do
put :calculate_winners
end
resources :budget_groups do resources :budget_groups do
resources :budget_headings do resources :budget_headings do
end end