extracts reclassification to a module
This commit is contained in:
@@ -5,6 +5,7 @@ class Budget
|
||||
include Sanitizable
|
||||
include Taggable
|
||||
include Searchable
|
||||
include Reclassification
|
||||
|
||||
acts_as_votable
|
||||
acts_as_paranoid column: :hidden_at
|
||||
@@ -61,7 +62,6 @@ 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 }
|
||||
@@ -243,43 +243,6 @@ class Budget
|
||||
investments
|
||||
end
|
||||
|
||||
def check_for_reclassification
|
||||
if heading_changed?
|
||||
log_heading_change
|
||||
store_reclassified_votes("heading_changed")
|
||||
remove_reclassified_votes
|
||||
elsif marked_as_unfeasible?
|
||||
store_reclassified_votes("unfeasible")
|
||||
remove_reclassified_votes
|
||||
end
|
||||
end
|
||||
|
||||
def heading_changed?
|
||||
budget.balloting? && heading_id_changed?
|
||||
end
|
||||
|
||||
def log_heading_change
|
||||
update_column(:previous_heading_id, heading_id_was)
|
||||
end
|
||||
|
||||
def marked_as_unfeasible?
|
||||
budget.balloting? && feasibility_changed? && unfeasible?
|
||||
end
|
||||
|
||||
def store_reclassified_votes(reason)
|
||||
ballot_lines_for_investment.each do |line|
|
||||
Budget::ReclassifiedVote.create!(user: line.ballot.user, investment: self, reason: reason)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_reclassified_votes
|
||||
ballot_lines_for_investment.destroy_all
|
||||
end
|
||||
|
||||
def ballot_lines_for_investment
|
||||
Budget::Ballot::Line.by_investment(self.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_denormalized_ids
|
||||
|
||||
Reference in New Issue
Block a user