removes votes from reclassified investments
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user