Display the same results for stats and recounts

In the recounts we were incorrectly assuming the total amount included
the blank and invalid ballots.
This commit is contained in:
Javi Martín
2019-05-30 13:58:31 +02:00
parent 6881ee134a
commit 123196e4ed
4 changed files with 9 additions and 11 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -24,9 +24,9 @@
<tr>
<td><strong><%= t("admin.recounts.index.all_booths_total") %></strong></td>
<% unless @poll.budget_poll? %>
<td class="text-center" id="total_final"><%= @all_booths_counts[:final] %></td>
<td class="text-center" id="total_final"><%= @stats.total_participants_booth %></td>
<% end %>
<td class="text-center" id="total_system"><%= @all_booths_counts[:system] %></td>
<td class="text-center" id="total_system"><%= @stats.total_registered_booth %></td>
</tr>
</tbody>
</table>

View File

@@ -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,