Files
grecia/app/models/poll/ballot.rb
Javi Martín 27ed26d6f2 Remove unnecessary class names in relations
Just like we do in the Budget module, and in some places in the Poll and
Legislation modules, we don't need to specify the class name when the
name of the relation matches the name of a class in the same module.
2019-10-25 19:03:14 +02:00

36 lines
731 B
Ruby

class Poll::Ballot < ApplicationRecord
belongs_to :ballot_sheet
validates :ballot_sheet_id, presence: true
def verify
investments.each do |investment_id|
add_investment(investment_id)
end
end
def add_investment(investment_id)
investment = find_investment(investment_id)
if investment.present? && not_already_added?(investment)
ballot.add_investment(investment)
end
end
def investments
data.split(",")
end
def ballot
Budget::Ballot.find_by(poll_ballot: self)
end
def find_investment(investment_id)
ballot.budget.investments.find_by(id: investment_id)
end
def not_already_added?(investment)
ballot.lines.where(investment: investment).blank?
end
end