Recalculate heading winner investments when a winner is flagged as incompatible

This commit is contained in:
Bertocq
2017-07-03 18:15:44 +02:00
parent 640e0e1c2a
commit 99052485fb

View File

@@ -64,6 +64,7 @@ class Budget
scope :for_render, -> { includes(:heading) } scope :for_render, -> { includes(:heading) }
before_save :calculate_confidence_score before_save :calculate_confidence_score
after_save :recalculate_heading_winners if :incompatible_changed?
before_validation :set_responsible_name before_validation :set_responsible_name
before_validation :set_denormalized_ids before_validation :set_denormalized_ids
@@ -201,6 +202,10 @@ class Budget
self.confidence_score = ScoreCalculator.confidence_score(total_votes, total_votes) self.confidence_score = ScoreCalculator.confidence_score(total_votes, total_votes)
end end
def recalculate_heading_winners
Budget::Result.new(budget, heading).calculate_winners if incompatible_changed? && winner? && incompatible?
end
def set_responsible_name def set_responsible_name
self.responsible_name = author.try(:document_number) if author.try(:document_number).present? self.responsible_name = author.try(:document_number) if author.try(:document_number).present?
end end