2024-02-07 17:29:47 +01:00
|
|
|
class ClonePiecesJustificativesService
|
|
|
|
def self.clone_attachments(original, kopy)
|
|
|
|
case original
|
|
|
|
when Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp
|
2024-02-16 11:20:08 +01:00
|
|
|
clone_many_attachments(original, kopy, :piece_justificative_file)
|
2024-02-07 17:29:47 +01:00
|
|
|
when TypeDeChamp
|
2024-02-16 11:20:08 +01:00
|
|
|
clone_one_attachment(original, kopy, :piece_justificative_template)
|
2024-02-07 17:29:47 +01:00
|
|
|
when Procedure
|
2024-02-16 11:20:08 +01:00
|
|
|
clone_one_attachment(original, kopy, :logo)
|
|
|
|
clone_one_attachment(original, kopy, :notice)
|
|
|
|
clone_one_attachment(original, kopy, :deliberation)
|
2024-02-07 17:29:47 +01:00
|
|
|
when AttestationTemplate
|
2024-02-16 11:20:08 +01:00
|
|
|
clone_one_attachment(original, kopy, :logo)
|
|
|
|
clone_one_attachment(original, kopy, :signature)
|
2024-02-07 17:29:47 +01:00
|
|
|
when Etablissement
|
2024-02-16 11:20:08 +01:00
|
|
|
clone_one_attachment(original, kopy, :entreprise_attestation_sociale)
|
|
|
|
clone_one_attachment(original, kopy, :entreprise_attestation_fiscale)
|
2024-02-07 17:29:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-16 11:20:08 +01:00
|
|
|
def self.clone_many_attachments(original, kopy, attachments_name)
|
|
|
|
original.public_send(attachments_name).attachments.each do |attachment|
|
|
|
|
kopy.public_send(attachments_name).attach(attachment.blob)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.clone_one_attachment(original, kopy, attachment_name)
|
2024-02-07 17:29:47 +01:00
|
|
|
attachment = original.public_send(attachment_name)
|
|
|
|
if attachment.attached?
|
|
|
|
kopy.public_send(attachment_name).attach(attachment.blob)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|