Add total Investments in the execution list
This commit is contained in:
9
app/helpers/budget_executions_helper.rb
Normal file
9
app/helpers/budget_executions_helper.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module BudgetExecutionsHelper
|
||||
|
||||
def filters_select_counts(status)
|
||||
@budget.investments.winners.with_milestones.select { |i| i.milestones
|
||||
.published.with_status.order_by_publication_date
|
||||
.last.status_id == status rescue false }.count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -84,6 +84,7 @@ class Budget
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
||||
scope :with_milestones, -> { joins(:milestones).distinct }
|
||||
|
||||
scope :by_budget, ->(budget) { where(budget: budget) }
|
||||
scope :by_group, ->(group_id) { where(group_id: group_id) }
|
||||
|
||||
@@ -57,9 +57,12 @@
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= label_tag t("budgets.executions.filters.label") %>
|
||||
<%= select_tag :status,
|
||||
options_from_collection_for_select(@statuses, :id, :name, params[:status]),
|
||||
options_from_collection_for_select(@statuses,
|
||||
:id, lambda { |s| "#{s.name} (#{filters_select_counts(s.id)})" },
|
||||
params[:status]),
|
||||
class: "js-submit-on-change",
|
||||
prompt: t("budgets.executions.filters.all") %>
|
||||
prompt: t("budgets.executions.filters.all",
|
||||
count: @budget.investments.winners.with_milestones.count) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ en:
|
||||
no_winner_investments: "No winner investments in this state"
|
||||
filters:
|
||||
label: "Project's current state"
|
||||
all: "All"
|
||||
all: "All (%{count})"
|
||||
phases:
|
||||
errors:
|
||||
dates_range_invalid: "Start date can't be equal or later than End date"
|
||||
|
||||
@@ -182,7 +182,7 @@ es:
|
||||
no_winner_investments: "No hay proyectos de gasto ganadores en este estado"
|
||||
filters:
|
||||
label: "Estado actual del proyecto"
|
||||
all: "Todos"
|
||||
all: "Todos (%{count})"
|
||||
phases:
|
||||
errors:
|
||||
dates_range_invalid: "La fecha de comienzo no puede ser igual o superior a la de finalización"
|
||||
|
||||
@@ -55,7 +55,7 @@ feature 'Executions' do
|
||||
|
||||
expect(page).not_to have_content('No winner investments in this state')
|
||||
|
||||
select 'Executed', from: 'status'
|
||||
select 'Executed (0)', from: 'status'
|
||||
|
||||
expect(page).to have_content('No winner investments in this state')
|
||||
end
|
||||
@@ -125,6 +125,25 @@ feature 'Executions' do
|
||||
let!(:status1) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.studying_project')) }
|
||||
let!(:status2) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.bidding')) }
|
||||
|
||||
scenario 'Filters select with counter are shown' do
|
||||
create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: Date.yesterday,
|
||||
status: status1)
|
||||
|
||||
create(:budget_investment_milestone, investment: investment2,
|
||||
publication_date: Date.yesterday,
|
||||
status: status2)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content("All (2)")
|
||||
expect(page).to have_content("#{status1.name} (1)")
|
||||
expect(page).to have_content("#{status2.name} (1)")
|
||||
end
|
||||
|
||||
scenario 'by milestone status', :js do
|
||||
create(:budget_investment_milestone, investment: investment1, status: status1)
|
||||
create(:budget_investment_milestone, investment: investment2, status: status2)
|
||||
@@ -138,17 +157,17 @@ feature 'Executions' do
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).to have_content(investment2.title)
|
||||
|
||||
select 'Studying the project', from: 'status'
|
||||
select 'Studying the project (1)', from: 'status'
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
|
||||
select 'Bidding', from: 'status'
|
||||
select 'Bidding (1)', from: 'status'
|
||||
|
||||
expect(page).to have_content(investment2.title)
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
|
||||
select 'Executing the project', from: 'status'
|
||||
select 'Executing the project (0)', from: 'status'
|
||||
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
@@ -167,10 +186,10 @@ feature 'Executions' do
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
select 'Studying the project', from: 'status'
|
||||
select 'Studying the project (0)', from: 'status'
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
|
||||
select 'Bidding', from: 'status'
|
||||
select 'Bidding (1)', from: 'status'
|
||||
expect(page).to have_content(investment1.title)
|
||||
end
|
||||
|
||||
@@ -187,10 +206,10 @@ feature 'Executions' do
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
select 'Studying the project', from: 'status'
|
||||
select 'Studying the project (1)', from: 'status'
|
||||
expect(page).to have_content(investment1.title)
|
||||
|
||||
select 'Bidding', from: 'status'
|
||||
select 'Bidding (0)', from: 'status'
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user