diff --git a/app/controllers/admin/poll/recounts_controller.rb b/app/controllers/admin/poll/recounts_controller.rb index a09e2af19..7e1756894 100644 --- a/app/controllers/admin/poll/recounts_controller.rb +++ b/app/controllers/admin/poll/recounts_controller.rb @@ -2,14 +2,12 @@ class Admin::Poll::RecountsController < Admin::Poll::BaseController before_action :load_poll def index + @stats = Poll::Stats.new(@poll) + @booth_assignments = @poll.booth_assignments. includes(:booth, :recounts, :voters). order("poll_booths.name"). page(params[:page]).per(50) - @all_booths_counts = { - final: ::Poll::Recount.select(:total_amount).where(booth_assignment_id: @poll.booth_assignment_ids).sum(:total_amount), - system: ::Poll::Voter.where(booth_assignment_id: @poll.booth_assignment_ids).count - } end private diff --git a/app/helpers/poll_recounts_helper.rb b/app/helpers/poll_recounts_helper.rb index 45eefd696..9524c06d7 100644 --- a/app/helpers/poll_recounts_helper.rb +++ b/app/helpers/poll_recounts_helper.rb @@ -1,7 +1,11 @@ module PollRecountsHelper def total_recounts_by_booth(booth_assignment) - booth_assignment.recounts.any? ? booth_assignment.recounts.to_a.sum(&:total_amount) : nil + if booth_assignment.recounts.any? + booth_assignment.recounts.sum(:total_amount) + + booth_assignment.recounts.sum(:white_amount) + + booth_assignment.recounts.sum(:null_amount) + end end end diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index d7e0031da..4a3815dfd 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -93,6 +93,10 @@ class Poll::Stats super + total_unregistered_booth end + def total_registered_booth + voters.where(origin: "booth").count + end + private def participant_ids @@ -107,10 +111,6 @@ class Poll::Stats @recounts ||= poll.recounts end - def total_registered_booth - voters.where(origin: "booth").count - end - def total_unregistered_booth [total_participants_booth - total_registered_booth, 0].max end diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index 61cda4668..577316838 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -24,9 +24,9 @@ <%= t("admin.recounts.index.all_booths_total") %> <% unless @poll.budget_poll? %> - <%= @all_booths_counts[:final] %> + <%= @stats.total_participants_booth %> <% end %> - <%= @all_booths_counts[:system] %> + <%= @stats.total_registered_booth %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c03001722..2cc2bc667 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1152,7 +1152,7 @@ en: result: table_whites: "Totally blank ballots" table_nulls: "Invalid ballots" - table_total: "Total ballots" + table_total: "Valid ballots" table_answer: Answer table_votes: Votes results_by_booth: diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 6fcaef57f..dd1d78a1b 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -51,7 +51,7 @@ en: select_booth: "Select booth" ballots_white: "Totally blank ballots" ballots_null: "Invalid ballots" - ballots_total: "Total ballots" + ballots_total: "Valid ballots" submit: "Save" results_list: "Your results" see_results: "See results" @@ -62,7 +62,7 @@ en: table_votes: Votes table_whites: "Totally blank ballots" table_nulls: "Invalid ballots" - table_total: "Total ballots" + table_total: "Valid ballots" residence: flash: create: "Document verified with Census" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 0e6a91fc0..356b3c01c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1151,7 +1151,7 @@ es: result: table_whites: "Papeletas totalmente en blanco" table_nulls: "Papeletas nulas" - table_total: "Papeletas totales" + table_total: "Papeletas válidas" table_answer: Respuesta table_votes: Votos results_by_booth: diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 82e6d1dcc..5586c6e62 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -51,7 +51,7 @@ es: select_booth: "Elige urna" ballots_white: "Papeletas totalmente en blanco" ballots_null: "Papeletas nulas" - ballots_total: "Papeletas totales" + ballots_total: "Papeletas válidas" submit: "Guardar" results_list: "Tus resultados" see_results: "Ver resultados" @@ -62,7 +62,7 @@ es: table_votes: Votos table_whites: "Papeletas totalmente en blanco" table_nulls: "Papeletas nulas" - table_total: "Papeletas totales" + table_total: "Papeletas válidas" residence: flash: create: "Documento verificado con el Padrón" diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 0a898c34e..42bce0f0b 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -273,7 +273,7 @@ describe "Admin polls" do end 2.times do - create(:poll_voter, poll: poll, booth_assignment: booth_assignment_final_recounted) + create(:poll_voter, :from_booth, poll: poll, booth_assignment: booth_assignment_final_recounted) end create(:poll_recount, diff --git a/spec/helpers/poll_recounts_helper_spec.rb b/spec/helpers/poll_recounts_helper_spec.rb new file mode 100644 index 000000000..dc34ce00a --- /dev/null +++ b/spec/helpers/poll_recounts_helper_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +describe PollRecountsHelper do + describe "#total_recounts_by_booth" do + it "includes blank and null votes" do + assignment = create(:poll_booth_assignment) + create(:poll_recount, :from_booth, booth_assignment: assignment, total_amount: 3, white_amount: 1) + create(:poll_recount, :from_booth, booth_assignment: assignment, total_amount: 4, null_amount: 2) + + expect(total_recounts_by_booth(assignment)).to eq 10 + end + end +end