fix(procedure): list piece justificative in repetitions

This commit is contained in:
Colin Darie 2023-11-23 14:51:48 +01:00
parent fce2d8efa9
commit 5d747ba0c2
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
4 changed files with 56 additions and 10 deletions

View file

@ -944,11 +944,15 @@ class Procedure < ApplicationRecord
end
def pieces_jointes_list_without_conditionnal
active_revision.types_de_champ_public.not_condition.filter(&:piece_justificative?)
pieces_jointes_list do |base_scope|
base_scope.where(types_de_champ: { condition: nil })
end
end
def pieces_jointes_list_with_conditionnal
active_revision.types_de_champ_public.where.not(condition: nil).filter(&:piece_justificative?)
pieces_jointes_list do |base_scope|
base_scope.where.not(types_de_champ: { condition: nil })
end
end
def toggle_routing
@ -961,6 +965,22 @@ class Procedure < ApplicationRecord
private
def pieces_jointes_list
scope = yield active_revision.revision_types_de_champ_public
.includes(:type_de_champ, revision_types_de_champ: :type_de_champ)
.where(types_de_champ: { type_champ: ['repetition', 'piece_justificative', 'titre_identite'] })
scope.each_with_object([]) do |rtdc, list|
if rtdc.type_de_champ.repetition?
rtdc.revision_types_de_champ.each do |rtdc_in_repetition|
list << [rtdc_in_repetition.type_de_champ, rtdc.type_de_champ] if rtdc_in_repetition.type_de_champ.piece_justificative?
end
else
list << [rtdc.type_de_champ]
end
end
end
def validate_auto_archive_on_in_the_future
return if auto_archive_on.nil?
return if auto_archive_on.future?

View file

@ -55,19 +55,13 @@
#accordion-116.fr-collapse
- if procedure.pieces_jointes_list_without_conditionnal.present?
%ul
- procedure.pieces_jointes_list_without_conditionnal.each do |pj|
%li
= pj.libelle
= t('utils.no_mandatory') if !pj.mandatory?
= render partial: "shared/procedure_pieces_jointes_list", collection: procedure.pieces_jointes_list_without_conditionnal, as: :pj
- if procedure.pieces_jointes_list_with_conditionnal.present?
%h3.fr-text--sm.fr-mb-0.fr-mt-2w
= t('shared.procedure_description.pieces_jointes_conditionnal_list_title')
%ul
- procedure.pieces_jointes_list_with_conditionnal.each do |pj|
%li
= pj.libelle
= t('utils.no_mandatory') if !pj.mandatory?
= render partial: "shared/procedure_pieces_jointes_list", collection: procedure.pieces_jointes_list_with_conditionnal, as: :pj
- if @usual_traitement_time.present?
%section.fr-accordion

View file

@ -0,0 +1,6 @@
- tdc, parent_tdc = pj
%li
= tdc.libelle
= "(#{parent_tdc.libelle})" if parent_tdc
= t('utils.no_mandatory') if !tdc.mandatory?

View file

@ -1693,6 +1693,32 @@ describe Procedure do
end
end
describe '#pieces_jointes_list' do
include Logic
let(:procedure) { create(:procedure, types_de_champ_public:) }
let(:types_de_champ_public) do
[
{ type: :integer_number, stable_id: 900 },
{ type: :piece_justificative, libelle: "PJ", mandatory: true, stable_id: 910 },
{ type: :piece_justificative, libelle: "PJ-cond", mandatory: true, stable_id: 911, condition: ds_eq(champ_value(900), constant(1)) },
{ type: :repetition, libelle: "Répétition", stable_id: 920, children: [{ type: :piece_justificative, libelle: "PJ2", stable_id: 921 }] }
]
end
let(:pj1) { procedure.active_revision.types_de_champ.find { _1.stable_id == 910 } }
let(:pjcond) { procedure.active_revision.types_de_champ.find { _1.stable_id == 911 } }
let(:repetition) { procedure.active_revision.types_de_champ.find { _1.stable_id == 920 } }
let(:pj2) { procedure.active_revision.types_de_champ.find { _1.stable_id == 921 } }
it "returns the list of pieces jointes without conditional" do
expect(procedure.pieces_jointes_list_without_conditionnal).to match_array([[pj1], [pj2, repetition]])
end
it "returns the list of pieces jointes having conditional" do
expect(procedure.pieces_jointes_list_with_conditionnal).to match_array([[pjcond]])
end
end
private
def create_dossier_with_pj_of_size(size, procedure)