Add Poll Total recount to officing and admin

This commit is contained in:
Bertocq
2017-09-14 14:00:02 +02:00
parent 1f867fb227
commit e8d748a881
9 changed files with 42 additions and 4 deletions

View File

@@ -28,6 +28,7 @@ class Officing::ResultsController < Officing::BaseController
where(date: index_params[:date])
@whites = ::Poll::WhiteResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
@nulls = ::Poll::NullResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
@total = ::Poll::TotalResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
end
end
@@ -70,6 +71,7 @@ class Officing::ResultsController < Officing::BaseController
build_white_results
build_null_results
build_total_results
end
def build_white_results
@@ -96,6 +98,18 @@ class Officing::ResultsController < Officing::BaseController
end
end
def build_total_results
if results_params[:total].present?
total_result = ::Poll::TotalResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date])
total_result.officer_assignment_id = @officer_assignment.id
total_result.amount = results_params[:total].to_i
total_result.author = current_user
total_result.origin = 'booth'
@results << total_result
end
end
def go_back_to_new(alert = nil)
params[:d] = results_params[:date]
params[:oa] = results_params[:officer_assignment_id]
@@ -132,7 +146,7 @@ class Officing::ResultsController < Officing::BaseController
end
def results_params
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls)
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls, :total)
end
def index_params

View File

@@ -14,11 +14,13 @@
<thead>
<th><%= t("admin.results.index.table_whites") %></th>
<th><%= t("admin.results.index.table_nulls") %></th>
<th><%= t("admin.results.index.table_total") %></th>
</thead>
<tbody>
<tr>
<td id="white_results"><%= @poll.white_results.sum(:amount) %></td>
<td id="null_results"><%= @poll.null_results.sum(:amount) %></td>
<td id="total_results"><%= @poll.total_results.sum(:amount) %></td>
</tr>
</tbody>
</table>

View File

@@ -16,12 +16,14 @@
<tr>
<th><%= t("officing.results.index.table_whites") %></th>
<th><%= t("officing.results.index.table_nulls") %></th>
<th><%= t("officing.results.index.table_total") %></th>
</tr>
</thead>
<tbody>
<tr>
<td id="white_results"><%= @whites %></td>
<td id="null_results"><%= @nulls %></td>
<td id="total_results"><%= @total %></td>
</tr>
</tbody>
</table>

View File

@@ -47,6 +47,11 @@
<h3><%= t("officing.results.new.ballots_null") %></h3>
<%= text_field_tag :nulls, params[:nulls].presence, placeholder: "0" %>
</div>
<div class="small-12 medium-6 large-3 column end">
<h3><%= t("officing.results.new.ballots_total") %></h3>
<%= text_field_tag :total, params[:total].presence, placeholder: "0" %>
</div>
</div>
<hr>

View File

@@ -612,6 +612,7 @@ en:
no_results: "There are no results"
table_whites: "Blank ballots"
table_nulls: "Invalid ballots"
table_total: "Total ballots"
table_answer: Answer
table_votes: Votes
booths:

View File

@@ -31,6 +31,7 @@ en:
select_date: "Select date"
ballots_white: "Blank ballots"
ballots_null: "Invalid ballots"
ballots_total: "Total ballots"
submit: "Save"
results_list: "Your results"
see_results: "See results"
@@ -41,6 +42,7 @@ en:
table_votes: Votes
table_whites: "Blank ballots"
table_nulls: "Invalid ballots"
table_total: "Total ballots"
residence:
flash:
create: "Document verified with Census"

View File

@@ -612,6 +612,7 @@ es:
no_results: "No hay resultados"
table_whites: Papeletas en blanco
table_nulls: Papeletas nulas
table_total: Papeletas totales
table_answer: Respuesta
table_votes: Votos
booths:

View File

@@ -31,6 +31,7 @@ es:
select_date: "Elige día"
ballots_white: "Papeletas en blanco"
ballots_null: "Papeletas nulas"
ballots_total: "Papeletas totales"
submit: "Guardar"
results_list: "Tus resultados"
see_results: "Ver resultados"
@@ -41,6 +42,7 @@ es:
table_votes: Votos
table_whites: Papeletas en blanco
table_nulls: Papeletas nulas
table_total: Papeletas totales
residence:
flash:
create: "Documento verificado con el Padrón"

View File

@@ -65,6 +65,7 @@ feature 'Officing Results' do
fill_in "whites", with: '66'
fill_in "nulls", with: '77'
fill_in "total", with: '88'
click_button 'Save'
@@ -101,6 +102,7 @@ feature 'Officing Results' do
fill_in "questions[#{@question_1.id}][1]", with: '200'
fill_in "whites", with: '6'
fill_in "nulls", with: '7'
fill_in "total", with: '8'
click_button 'Save'
@@ -113,6 +115,7 @@ feature 'Officing Results' do
expect(page).to_not have_content('7777')
within("#white_results") { expect(page).to have_content('6') }
within("#null_results") { expect(page).to have_content('7') }
within("#total_results") { expect(page).to have_content('8') }
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content('5555') }
within("#question_#{@question_1.id}_1_result") { expect(page).to have_content('200') }
end
@@ -134,6 +137,11 @@ feature 'Officing Results' do
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
amount: 44)
total_result = create(:poll_total_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
amount: 66)
visit officing_poll_results_path(@poll,
date: I18n.l(@poll.ends_at.to_date),
@@ -154,6 +162,7 @@ feature 'Officing Results' do
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
end