fix(dossier): improuve commune champ rendering in pdf

This commit is contained in:
Paul Chavard 2023-04-04 14:54:29 +02:00
parent ed33f1916a
commit 2a48228552
4 changed files with 14 additions and 7 deletions

View file

@ -25,7 +25,7 @@ class Champs::CommuneChamp < Champs::TextChamp
before_validation :on_code_postal_change
def for_export
[name, code, departement? ? departement_code_and_name : '']
[name, code? ? code : '', departement? ? departement_code_and_name : '']
end
def departement_name

View file

@ -170,14 +170,14 @@ def add_single_champ(pdf, champ)
add_identite_etablissement(pdf, champ.etablissement)
end
when 'Champs::NumberChamp'
value = champ.to_s.empty? ? 'Non communiqué' : number_with_delimiter(champ.to_s)
value = champ.blank? ? 'Non communiqué' : number_with_delimiter(champ.to_s)
format_in_2_lines(pdf, tdc.libelle, value)
when 'Champs::CommuneChamp'
value = champ.to_s.empty? ? 'Non communiqué' : champ.to_s
value = champ.blank? ? 'Non communiqué' : champ.to_s
format_in_2_lines(pdf, tdc.libelle, value)
pdf.text "Département : #{champ.departement}" if champ.departement.present?
pdf.text "Département : #{champ.departement_code_and_name}" if champ.departement?
else
value = champ.to_s.empty? ? 'Non communiqué' : champ.to_s
value = champ.blank? ? 'Non communiqué' : champ.to_s
format_in_2_lines(pdf, tdc.libelle, value)
end
end

View file

@ -738,6 +738,13 @@ describe Instructeurs::DossiersController, type: :controller do
it { expect(assigns(:include_infos_administration)).to eq(true) }
it { expect(assigns(:is_dossier_in_batch_operation)).to eq(false) }
it { expect(response).to render_template 'dossiers/show' }
context 'empty champs commune' do
let(:procedure) { create(:procedure, :published, :with_commune, instructeurs:) }
let(:dossier) { create(:dossier, :accepte, procedure:) }
it { expect(response).to render_template 'dossiers/show' }
end
end
context 'with dossier in batch_operation' do

View file

@ -1680,8 +1680,8 @@ describe Dossier do
[
[yes_no_tdc.libelle, "Oui"],
[text_tdc.libelle, "text"],
["commune", nil],
["commune (Code insee)", nil],
["commune", ''],
["commune (Code insee)", ''],
["commune (Département)", ""]
]
end