Add attestation, justificatifs, operation_logs and bill_signatures to dossier export

This commit is contained in:
Paul Chavard 2020-12-08 16:34:38 +01:00 committed by simon lehericey
parent 1fe1fa7a98
commit a2e87cbb56
4 changed files with 42 additions and 10 deletions

View file

@ -23,15 +23,29 @@ class ActiveStorage::DownloadableFile
private
def self.timestamped_filename(piece_justificative)
def self.timestamped_filename(attachment)
# we pad the original file name with a timestamp
# and a short id in order to help identify multiple versions and avoid name collisions
extension = File.extname(piece_justificative.filename.to_s)
basename = File.basename(piece_justificative.filename.to_s, extension)
timestamp = piece_justificative.created_at.strftime("%d-%m-%Y-%H-%M")
id = piece_justificative.id % 10000
folder = self.folder(attachment)
extension = File.extname(attachment.filename.to_s)
basename = File.basename(attachment.filename.to_s, extension)
timestamp = attachment.created_at.strftime("%d-%m-%Y-%H-%M")
id = attachment.id % 10000
"#{basename}-#{timestamp}-#{id}#{extension}"
"#{folder}/#{basename}-#{timestamp}-#{id}#{extension}"
end
def self.folder(attachment)
case attachment.record_type
when 'Dossier'
'dossier'
when 'DossierOperationLog', 'BillSignature'
'horodatage'
when 'Commentaire'
'messagerie'
else
'pieces_justificatives'
end
end
def using_local_backend?

View file

@ -2,8 +2,9 @@ class PiecesJustificativesService
def self.liste_pieces_justificatives(dossier)
pjs_champs = pjs_for_champs(dossier)
pjs_commentaires = pjs_for_commentaires(dossier)
pjs_dossier = pjs_for_dossier(dossier)
(pjs_champs + pjs_commentaires)
(pjs_champs + pjs_commentaires + pjs_dossier)
.filter(&:attached?)
end
@ -59,4 +60,18 @@ class PiecesJustificativesService
.commentaires
.map(&:piece_jointe)
end
def self.pjs_for_dossier(dossier)
bill_signatures = dossier.dossier_operation_logs.map(&:bill_signature).compact.uniq
[
dossier.justificatif_motivation,
dossier.attestation&.pdf,
dossier.etablissement&.entreprise_attestation_sociale,
dossier.etablissement&.entreprise_attestation_fiscale,
dossier.dossier_operation_logs.map(&:serialized),
bill_signatures.map(&:serialized),
bill_signatures.map(&:signature)
].flatten.compact
end
end