diff --git a/app/models/concerns/dossier_sections_concern.rb b/app/models/concerns/dossier_sections_concern.rb index bd8166efe..57ddf0ccf 100644 --- a/app/models/concerns/dossier_sections_concern.rb +++ b/app/models/concerns/dossier_sections_concern.rb @@ -22,14 +22,19 @@ module DossierSectionsConcern def index_for_section_header(champ) champs = champ.private? ? champs_private : champs_public - index = 1 champs.each do |c| - return index if c.stable_id == champ.stable_id - next unless c.visible? + if c.repetition? + index_in_repetition = c.rows.flatten.filter { _1.stable_id == champ.stable_id }.find_index(champ) + return "#{index}.#{index_in_repetition + 1}" if index_in_repetition + else + return index if c.stable_id == champ.stable_id + next unless c.visible? - index += 1 if c.type_de_champ.header_section? + index += 1 if c.type_de_champ.header_section? + end end + index end end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 5dc4d8f28..7d18d0301 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1317,6 +1317,18 @@ describe Dossier do end end + describe 'index_for_section_header' do + let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) } + let(:dossier) { create(:dossier, procedure: procedure) } + let(:types_de_champ) { [{ type: :repetition, mandatory: true, children: [{ type: :header_section }] }] } + + it 'index classly' do + repetition = dossier.champs.find(&:repetition?) + header_in_repetition = repetition.champs.find(&:header_section?) + expect(dossier.index_for_section_header(header_in_repetition)).to eq("1.1") + end + end + describe '#repasser_en_instruction!' do let(:dossier) { create(:dossier, :refuse, :with_attestation, archived: true, termine_close_to_expiration_notice_sent_at: Time.zone.now) } let!(:instructeur) { create(:instructeur) }