Files
nairobi/app/models/poll/booth_assignment.rb
Javi Martín a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00

37 lines
803 B
Ruby

class Poll
class BoothAssignment < ApplicationRecord
belongs_to :booth
belongs_to :poll
delegate :name, to: :booth
before_destroy :destroy_poll_shifts
has_many :officer_assignments, dependent: :destroy
has_many :officers, through: :officer_assignments
has_many :voters
has_many :partial_results
has_many :recounts
def shifts?
!shifts.empty?
end
def unable_to_destroy?
(partial_results.count + recounts.count).positive?
end
private
def shifts
Poll::Shift.where(booth_id: booth_id,
officer_id: officer_assignments.pluck(:officer_id),
date: officer_assignments.pluck(:date))
end
def destroy_poll_shifts
shifts.destroy_all
end
end
end