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:
@@ -2,14 +2,12 @@ class Admin::Poll::RecountsController < Admin::Poll::BaseController
|
|||||||
before_action :load_poll
|
before_action :load_poll
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@stats = Poll::Stats.new(@poll)
|
||||||
|
|
||||||
@booth_assignments = @poll.booth_assignments.
|
@booth_assignments = @poll.booth_assignments.
|
||||||
includes(:booth, :recounts, :voters).
|
includes(:booth, :recounts, :voters).
|
||||||
order("poll_booths.name").
|
order("poll_booths.name").
|
||||||
page(params[:page]).per(50)
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ class Poll::Stats
|
|||||||
super + total_unregistered_booth
|
super + total_unregistered_booth
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def total_registered_booth
|
||||||
|
voters.where(origin: "booth").count
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def participant_ids
|
def participant_ids
|
||||||
@@ -107,10 +111,6 @@ class Poll::Stats
|
|||||||
@recounts ||= poll.recounts
|
@recounts ||= poll.recounts
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_registered_booth
|
|
||||||
voters.where(origin: "booth").count
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_unregistered_booth
|
def total_unregistered_booth
|
||||||
[total_participants_booth - total_registered_booth, 0].max
|
[total_participants_booth - total_registered_booth, 0].max
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><strong><%= t("admin.recounts.index.all_booths_total") %></strong></td>
|
<td><strong><%= t("admin.recounts.index.all_booths_total") %></strong></td>
|
||||||
<% unless @poll.budget_poll? %>
|
<% 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 %>
|
<% 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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ describe "Admin polls" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
2.times do
|
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
|
end
|
||||||
|
|
||||||
create(:poll_recount,
|
create(:poll_recount,
|
||||||
|
|||||||
Reference in New Issue
Block a user