diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb
index 8ffa455c8..7998f29a2 100644
--- a/app/controllers/admin/poll/booth_assignments_controller.rb
+++ b/app/controllers/admin/poll/booth_assignments_controller.rb
@@ -18,6 +18,8 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
@booth_assignment = @poll.booth_assignments.includes(:recounts, :voters,
officer_assignments: [officer: [:user]]).find(params[:id])
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
+ @partial_results = @booth_assignment.partial_results
+ @recounts = @booth_assignment.recounts
end
def create
diff --git a/app/views/admin/poll/booth_assignments/_results.html.erb b/app/views/admin/poll/booth_assignments/_results.html.erb
new file mode 100644
index 000000000..fdbc4da3f
--- /dev/null
+++ b/app/views/admin/poll/booth_assignments/_results.html.erb
@@ -0,0 +1,12 @@
+
+
<%= t("admin.results.index.title") %>
+
+ <% if @partial_results.empty? %>
+
+ <%= t("admin.results.index.no_results") %>
+
+ <% else %>
+ <%= render "admin/poll/results/recount", resource: @booth_assignment %>
+ <%= render "admin/poll/results/result" %>
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb
index fd303d099..71938cce5 100644
--- a/app/views/admin/poll/booth_assignments/show.html.erb
+++ b/app/views/admin/poll/booth_assignments/show.html.erb
@@ -17,9 +17,12 @@
<%= link_to t("admin.poll_booth_assignments.show.officers"), "#tab-officers" %>
-
+
<%= link_to t("admin.poll_booth_assignments.show.recounts"), "#tab-recounts" %>
+
+ <%= link_to t("admin.poll_booth_assignments.show.results"), "#tab-results" %>
+
@@ -43,7 +46,7 @@
<% end %>
-
+
<%= t("admin.poll_booth_assignments.show.recounts_list") %>
@@ -55,8 +58,12 @@
- | <%= total_recounts_by_booth(@booth_assignment) || '-' %> |
- <%= @booth_assignment.voters.count %> |
+
+ <%= total_recounts_by_booth(@booth_assignment) || '-' %>
+ |
+
+ <%= @booth_assignment.voters.count %>
+ |
@@ -79,4 +86,7 @@
+
+ <%= render "results" %>
+
diff --git a/app/views/admin/poll/results/_recount.html.erb b/app/views/admin/poll/results/_recount.html.erb
new file mode 100644
index 000000000..f4ab43954
--- /dev/null
+++ b/app/views/admin/poll/results/_recount.html.erb
@@ -0,0 +1,14 @@
+
+
+ | <%= t("admin.results.result.table_whites") %> |
+ <%= t("admin.results.result.table_nulls") %> |
+ <%= t("admin.results.result.table_total") %> |
+
+
+
+ | <%= resource.recounts.sum(:white_amount) %> |
+ <%= resource.recounts.sum(:null_amount) %> |
+ <%= resource.recounts.sum(:total_amount) %> |
+
+
+
\ No newline at end of file
diff --git a/app/views/admin/poll/results/_result.html.erb b/app/views/admin/poll/results/_result.html.erb
new file mode 100644
index 000000000..e2fe5f037
--- /dev/null
+++ b/app/views/admin/poll/results/_result.html.erb
@@ -0,0 +1,21 @@
+<% by_question = @partial_results.group_by(&:question_id) %>
+<% @poll.questions.each do |question| %>
+ <%= question.title %>
+
+
+
+ | <%= t("admin.results.result.table_answer") %> |
+ <%= t("admin.results.result.table_votes") %> |
+
+
+
+ <% question.question_answers.each_with_index do |answer, i| %>
+ <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
+
+ | <%= answer.title %> |
+ <%= by_answer[answer.title].present? ? by_answer[answer.title].sum(&:amount) : 0 %> |
+
+ <% end %>
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/poll/results/_results_by_booth.html.erb b/app/views/admin/poll/results/_results_by_booth.html.erb
new file mode 100644
index 000000000..9266a58fb
--- /dev/null
+++ b/app/views/admin/poll/results/_results_by_booth.html.erb
@@ -0,0 +1,20 @@
+<%= t("admin.results.results_by_booth.title") %>
+
+
+
+ | <%= t("admin.results.results_by_booth.booth") %> |
+ <%= t("admin.results.results_by_booth.results") %> |
+
+
+
+ <% @poll.booth_assignments.sort_by {|ba| ba.booth.name }.each do |booth_assignment| %>
+
+ | <%= booth_assignment.booth.name %> |
+
+ <%= link_to t("admin.results.results_by_booth.see_results"),
+ admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: "tab-results") %>
+ |
+
+ <% end %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/poll/results/index.html.erb b/app/views/admin/poll/results/index.html.erb
index ab4e94857..7f21e5452 100644
--- a/app/views/admin/poll/results/index.html.erb
+++ b/app/views/admin/poll/results/index.html.erb
@@ -9,44 +9,8 @@
<%= t("admin.results.index.no_results") %>
<% else %>
-
-
-
- | <%= t("admin.results.index.table_whites") %> |
- <%= t("admin.results.index.table_nulls") %> |
- <%= t("admin.results.index.table_total") %> |
-
-
-
- | <%= @poll.recounts.sum(:white_amount) %> |
- <%= @poll.recounts.sum(:null_amount) %> |
- <%= @poll.recounts.sum(:total_amount) %> |
-
-
-
-
-
- <% by_question = @partial_results.group_by(&:question_id) %>
- <% @poll.questions.each do |question| %>
- <%= question.title %>
-
-
-
- | <%= t("admin.results.index.table_answer") %> |
- <%= t("admin.results.index.table_votes") %> |
-
-
-
- <% question.question_answers.each_with_index do |answer, i| %>
- <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
-
- | <%= answer.title %> |
- <%= by_answer[answer.title].present? ? by_answer[answer.title].sum(&:amount) : 0 %> |
-
- <% end %>
-
-
- <% end %>
-
+ <%= render "recount", resource: @poll %>
+ <%= render "result" %>
+ <%= render "results_by_booth" %>
<% end %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 87bbb6685..38abe6f56 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -537,6 +537,7 @@ en:
no_officers: "There are no officers for this booth"
recounts: "Recounts"
recounts_list: "Recount list for this booth"
+ results: "Results"
date: "Date"
count_final: "Final recount (by officer)"
count_by_system: "Votes (automatic)"
@@ -647,11 +648,17 @@ en:
index:
title: "Results"
no_results: "There are no results"
+ result:
table_whites: "Totally blank ballots"
table_nulls: "Invalid ballots"
table_total: "Total ballots"
table_answer: Answer
table_votes: Votes
+ results_by_booth:
+ booth: Booth
+ results: Results
+ see_results: See results
+ title: "Results by booth"
booths:
index:
title: "List of booths"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 0aa73ffb2..3336cdc5b 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -537,6 +537,7 @@ es:
no_officers: "No hay presidentes de mesa para esta urna"
recounts: "Recuentos"
recounts_list: "Lista de recuentos de esta urna"
+ results: "Resultados"
date: "Fecha"
count_final: "Recuento final (presidente de mesa)"
count_by_system: "Votos (automático)"
@@ -649,11 +650,17 @@ es:
index:
title: "Resultados"
no_results: "No hay resultados"
+ result:
table_whites: Papeletas totalmente en blanco
table_nulls: Papeletas nulas
table_total: Papeletas totales
table_answer: Respuesta
table_votes: Votos
+ results_by_booth:
+ booth: Urna
+ results: Resultados
+ see_results: Ver resultados
+ title: "Resultados por urna"
booths:
index:
title: "Lista de urnas"
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index 18bfe0dcb..8c09923d8 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -640,6 +640,49 @@ print "Creating Poll Voters"
Poll::Voter.create(poll: poll, user: user)
end
+puts " ✅"
+print "Creating Poll Recounts"
+
+Poll.all.each do |poll|
+ poll.booth_assignments.each do |booth_assignment|
+ officer_assignment = poll.officer_assignments.first
+ author = Poll::Officer.first.user
+
+ Poll::Recount.create!(officer_assignment: officer_assignment,
+ booth_assignment: booth_assignment,
+ author: author,
+ date: poll.ends_at,
+ white_amount: rand(0..10),
+ null_amount: rand(0..10),
+ total_amount: rand(100..9999),
+ origin: "booth")
+ end
+end
+
+puts " ✅"
+print "Creating Poll Results"
+
+Poll.all.each do |poll|
+ poll.booth_assignments.each do |booth_assignment|
+ officer_assignment = poll.officer_assignments.first
+ author = Poll::Officer.first.user
+
+ poll.questions.each do |question|
+ question.question_answers.each do |answer|
+ Poll::PartialResult.create!(officer_assignment: officer_assignment,
+ booth_assignment: booth_assignment,
+ date: Date.current,
+ question: question,
+ answer: answer.title,
+ author: author,
+ amount: rand(999),
+ origin: "booth")
+ end
+ end
+ end
+
+end
+
puts " ✅"
print "Creating legislation processes"
diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb
index 77881efaa..5813e2dac 100644
--- a/spec/features/admin/poll/booth_assigments_spec.rb
+++ b/spec/features/admin/poll/booth_assigments_spec.rb
@@ -126,5 +126,104 @@ feature 'Admin booths assignments' do
end
end
+ scenario 'Results for a booth assignment' do
+ poll = create(:poll)
+ booth_assignment = create(:poll_booth_assignment, poll: poll)
+ other_booth_assignment = create(:poll_booth_assignment, poll: poll)
+
+ question_1 = create(:poll_question, poll: poll)
+ create(:poll_question_answer, title: 'Yes', question: question_1)
+ create(:poll_question_answer, title: 'No', question: question_1)
+
+ question_2 = create(:poll_question, poll: poll)
+ create(:poll_question_answer, title: 'Today', question: question_2)
+ create(:poll_question_answer, title: 'Tomorrow', question: question_2)
+
+ create(:poll_partial_result,
+ booth_assignment: booth_assignment,
+ question: question_1,
+ answer: 'Yes',
+ amount: 11)
+
+ create(:poll_partial_result,
+ booth_assignment: booth_assignment,
+ question: question_1,
+ answer: 'No',
+ amount: 4)
+
+ create(:poll_partial_result,
+ booth_assignment: booth_assignment,
+ question: question_2,
+ answer: 'Today',
+ amount: 5)
+
+ create(:poll_partial_result,
+ booth_assignment: booth_assignment,
+ question: question_2,
+ answer: 'Tomorrow',
+ amount: 6)
+
+ create(:poll_partial_result,
+ booth_assignment: other_booth_assignment,
+ question: question_1,
+ answer: 'Yes',
+ amount: 9999)
+
+ create(:poll_recount,
+ booth_assignment: booth_assignment,
+ white_amount: 21,
+ null_amount: 44,
+ total_amount: 66)
+
+ create(:poll_recount,
+ booth_assignment: other_booth_assignment,
+ white_amount: 999,
+ null_amount: 999,
+ total_amount: 999)
+
+ visit admin_poll_booth_assignment_path(poll, booth_assignment)
+
+ click_link 'Results'
+
+ expect(page).to have_content(question_1.title)
+
+ within("#question_#{question_1.id}_0_result") do
+ expect(page).to have_content("Yes")
+ expect(page).to have_content(11)
+ end
+
+ within("#question_#{question_1.id}_1_result") do
+ expect(page).to have_content("No")
+ expect(page).to have_content(4)
+ end
+
+ expect(page).to have_content(question_2.title)
+
+ within("#question_#{question_2.id}_0_result") do
+ expect(page).to have_content("Today")
+ expect(page).to have_content(5)
+ end
+
+ within("#question_#{question_2.id}_1_result") do
+ expect(page).to have_content("Tomorrow")
+ expect(page).to have_content(6)
+ end
+
+ within('#white_results') { expect(page).to have_content('21') }
+ within('#null_results') { expect(page).to have_content('44') }
+ within('#total_results') { expect(page).to have_content('66') }
+ end
+
+ scenario "No results" do
+ poll = create(:poll)
+ booth_assignment = create(:poll_booth_assignment, poll: poll)
+
+ visit admin_poll_booth_assignment_path(poll, booth_assignment)
+
+ click_link "Results"
+
+ expect(page).to have_content "There are no results"
+ end
+
end
end
diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb
index 9c2d3fcf1..2a2d26ea5 100644
--- a/spec/features/admin/poll/polls_spec.rb
+++ b/spec/features/admin/poll/polls_spec.rb
@@ -311,6 +311,43 @@ feature 'Admin polls' do
within('#null_results') { expect(page).to have_content('44') }
within('#total_results') { expect(page).to have_content('66') }
end
+
+ scenario "Link to results by booth" do
+ poll = create(:poll)
+ booth_assignment1 = create(:poll_booth_assignment, poll: poll)
+ booth_assignment2 = create(:poll_booth_assignment, poll: poll)
+
+ question = create(:poll_question, poll: poll)
+ create(:poll_question_answer, title: 'Yes', question: question)
+ create(:poll_question_answer, title: 'No', question: question)
+
+ create(:poll_partial_result,
+ booth_assignment: booth_assignment1,
+ question: question,
+ answer: 'Yes',
+ amount: 5)
+
+ create(:poll_partial_result,
+ booth_assignment: booth_assignment2,
+ question: question,
+ answer: 'Yes',
+ amount: 6)
+
+ visit admin_poll_path(poll)
+
+ click_link "Results"
+
+ expect(page).to have_link("See results", count: 2)
+
+ within("#booth_assignment_#{booth_assignment1.id}_result") do
+ click_link "See results"
+ end
+
+ expect(page).to have_content booth_assignment1.booth.name
+ expect(page).to have_content "Results"
+ expect(page).to have_content "Yes"
+ expect(page).to have_content "5"
+ end
end
end