[#1421] Move piece justificative specific validation to PieceJustificativeChamp

This commit is contained in:
Frederic Merizen 2018-06-14 17:44:03 +02:00 committed by Pierre de La Morinerie
parent c690d3819e
commit c2f199c5aa
2 changed files with 7 additions and 5 deletions

View file

@ -41,11 +41,7 @@ class Champ < ApplicationRecord
end end
def mandatory_and_blank? def mandatory_and_blank?
if type_champ == 'piece_justificative' mandatory? && value.blank?
mandatory? && !piece_justificative_file.attached?
else
mandatory? && value.blank?
end
end end
def same_date?(num, compare) def same_date?(num, compare)

View file

@ -1,6 +1,12 @@
class Champs::PieceJustificativeChamp < Champ class Champs::PieceJustificativeChamp < Champ
after_commit :create_virus_scan after_commit :create_virus_scan
def mandatory_and_blank?
mandatory? && !piece_justificative_file.attached?
end
private
def create_virus_scan def create_virus_scan
if self.piece_justificative_file&.attachment&.blob.present? if self.piece_justificative_file&.attachment&.blob.present?
VirusScan.where(champ: self).where.not(blob_key: self.piece_justificative_file.blob.key).delete_all VirusScan.where(champ: self).where.not(blob_key: self.piece_justificative_file.blob.key).delete_all