removes votes from reclassified investments

This commit is contained in:
rgarcia
2017-05-13 13:10:04 +02:00
parent aca9866d4e
commit 1ca16d9d40
5 changed files with 156 additions and 1 deletions

View File

@@ -61,6 +61,7 @@ class Budget
before_save :calculate_confidence_score
before_validation :set_responsible_name
before_validation :set_denormalized_ids
after_save :check_for_reclassification
def self.filter_params(params)
params.select{|x,_| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s }
@@ -242,6 +243,25 @@ class Budget
investments
end
def check_for_reclassification
if reclassified?
log_reclassification
remove_reclassified_votes
end
end
def reclassified?
budget.balloting? && heading_id_changed?
end
def log_reclassification
self.previous_heading_id = self.heading_id_was
end
def remove_reclassified_votes
Budget::Ballot::Line.where(investment: self).destroy_all
end
private
def set_denormalized_ids