diff --git a/app/models/failed_census_call.rb b/app/models/failed_census_call.rb index ac792d7b7..b7d60e63a 100644 --- a/app/models/failed_census_call.rb +++ b/app/models/failed_census_call.rb @@ -1,3 +1,4 @@ class FailedCensusCall < ActiveRecord::Base belongs_to :user, counter_cache: true + belongs_to :poll_officer, class_name: 'Poll::Officer', counter_cache: true end diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index fbae39562..bbb6d757b 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -41,6 +41,17 @@ class Officing::Residence end end + def store_failed_census_call + FailedCensusCall.create({ + user: user, + document_number: document_number, + document_type: document_type, + year_of_birth: year_of_birth, + poll_officer: officer + }) + + end + def user_exists? find_user_by_document.present? end @@ -54,6 +65,7 @@ class Officing::Residence return if errors.any? unless residency_valid? + store_failed_census_call errors.add(:residence_in_madrid, false) end end diff --git a/app/models/poll/officer.rb b/app/models/poll/officer.rb index 81a2afd5d..bf4c73c36 100644 --- a/app/models/poll/officer.rb +++ b/app/models/poll/officer.rb @@ -2,6 +2,7 @@ class Poll class Officer < ActiveRecord::Base belongs_to :user has_many :officer_assignments, class_name: "Poll::OfficerAssignment" + has_many :failed_census_calls, foreign_key: :poll_officer_id validates :user_id, presence: true, uniqueness: true @@ -22,4 +23,4 @@ class Poll end end -end \ No newline at end of file +end