diff --git a/app/models/champ.rb b/app/models/champ.rb index e3434f307..49023ac09 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -41,11 +41,7 @@ class Champ < ApplicationRecord end def mandatory_and_blank? - if type_champ == 'piece_justificative' - mandatory? && !piece_justificative_file.attached? - else - mandatory? && value.blank? - end + mandatory? && value.blank? end def same_date?(num, compare) diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 4c4270609..8373686f7 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -1,6 +1,12 @@ class Champs::PieceJustificativeChamp < Champ after_commit :create_virus_scan + def mandatory_and_blank? + mandatory? && !piece_justificative_file.attached? + end + + private + def create_virus_scan if self.piece_justificative_file&.attachment&.blob.present? VirusScan.where(champ: self).where.not(blob_key: self.piece_justificative_file.blob.key).delete_all