fix dossier directory for attestation when export with export template
This commit is contained in:
parent
4232cc98c7
commit
2267ec98cf
3 changed files with 18 additions and 1 deletions
|
@ -128,6 +128,8 @@ class ExportTemplate < ApplicationRecord
|
||||||
'messagerie'
|
'messagerie'
|
||||||
when 'Avis'
|
when 'Avis'
|
||||||
'avis'
|
'avis'
|
||||||
|
when 'Attestation'
|
||||||
|
'pieces_justificatives'
|
||||||
else
|
else
|
||||||
# for attachment
|
# for attachment
|
||||||
return attachment_path(dossier, attachment, index, row_index, champ)
|
return attachment_path(dossier, attachment, index, row_index, champ)
|
||||||
|
|
|
@ -227,9 +227,14 @@ class PiecesJustificativesService
|
||||||
.where(record_type: "Attestation", record_id: attestation_id_dossier_id.keys)
|
.where(record_type: "Attestation", record_id: attestation_id_dossier_id.keys)
|
||||||
.map do |a|
|
.map do |a|
|
||||||
dossier_id = attestation_id_dossier_id[a.record_id]
|
dossier_id = attestation_id_dossier_id[a.record_id]
|
||||||
|
if @export_template
|
||||||
|
dossier = dossiers.find { _1.id == dossier_id }
|
||||||
|
@export_template.attachment_and_path(dossier, a)
|
||||||
|
else
|
||||||
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
|
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def pjs_for_avis(dossiers)
|
def pjs_for_avis(dossiers)
|
||||||
avis_ids_dossier_id_query = Avis.joins(:dossier).where(dossier: dossiers)
|
avis_ids_dossier_id_query = Avis.joins(:dossier).where(dossier: dossiers)
|
||||||
|
|
|
@ -209,6 +209,16 @@ describe PiecesJustificativesService do
|
||||||
let!(:witness) { create(:dossier, :with_attestation) }
|
let!(:witness) { create(:dossier, :with_attestation) }
|
||||||
|
|
||||||
it { expect(subject).to match_array(dossier.attestation.pdf.attachment) }
|
it { expect(subject).to match_array(dossier.attestation.pdf.attachment) }
|
||||||
|
it 'uses default name for dossier directory' do
|
||||||
|
expect(PiecesJustificativesService.new(user_profile:, export_template: nil).liste_documents(dossiers).map(&:second)[0].starts_with?("dossier-#{dossier.id}/pieces_justificatives")).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with export_template' do
|
||||||
|
let(:export_template) { create(:export_template, :with_custom_ddd_prefix, ddd_prefix: "DOSSIER-", groupe_instructeur: procedure.defaut_groupe_instructeur) }
|
||||||
|
it 'uses specific name for dossier directory' do
|
||||||
|
expect(PiecesJustificativesService.new(user_profile:, export_template:).liste_documents(dossiers).map(&:second)[0].starts_with?("DOSSIER-#{dossier.id}/pieces_justificatives")).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with an etablissement' do
|
context 'with an etablissement' do
|
||||||
|
|
Loading…
Reference in a new issue