[#2180] When cloning a procedure, convert types de PJ to types de champ PJ
This commit is contained in:
parent
33f7773a23
commit
651fd6149b
3 changed files with 48 additions and 9 deletions
|
@ -187,7 +187,6 @@ class Procedure < ApplicationRecord
|
||||||
populate_champ_stable_ids
|
populate_champ_stable_ids
|
||||||
procedure = self.deep_clone(include:
|
procedure = self.deep_clone(include:
|
||||||
{
|
{
|
||||||
types_de_piece_justificative: nil,
|
|
||||||
attestation_template: nil,
|
attestation_template: nil,
|
||||||
types_de_champ: :drop_down_list,
|
types_de_champ: :drop_down_list,
|
||||||
types_de_champ_private: :drop_down_list
|
types_de_champ_private: :drop_down_list
|
||||||
|
@ -203,6 +202,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
[:notice, :deliberation].each { |attachment| clone_attachment(procedure, attachment) }
|
[:notice, :deliberation].each { |attachment| clone_attachment(procedure, attachment) }
|
||||||
|
|
||||||
|
procedure.types_de_champ += PiecesJustificativesService.types_pj_as_types_de_champ(self)
|
||||||
procedure.administrateur = admin
|
procedure.administrateur = admin
|
||||||
procedure.initiated_mail = initiated_mail&.dup
|
procedure.initiated_mail = initiated_mail&.dup
|
||||||
procedure.received_mail = received_mail&.dup
|
procedure.received_mail = received_mail&.dup
|
||||||
|
|
|
@ -31,4 +31,37 @@ class PiecesJustificativesService
|
||||||
|
|
||||||
missing_pjs.map { |pj| "La pièce jointe #{pj.libelle.truncate(200)} doit être fournie." }
|
missing_pjs.map { |pj| "La pièce jointe #{pj.libelle.truncate(200)} doit être fournie." }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.types_pj_as_types_de_champ(procedure)
|
||||||
|
order_place = procedure.types_de_champ.last&.order_place || 0
|
||||||
|
types_de_champ = [
|
||||||
|
TypeDeChamp.new(
|
||||||
|
libelle: "Pièces jointes",
|
||||||
|
type_champ: TypeDeChamp.type_champs.fetch(:header_section),
|
||||||
|
order_place: order_place
|
||||||
|
)
|
||||||
|
]
|
||||||
|
types_de_champ += procedure.types_de_piece_justificative.map do |tpj|
|
||||||
|
order_place += 1
|
||||||
|
description = tpj.description
|
||||||
|
if tpj.lien_demarche.present?
|
||||||
|
if description.present?
|
||||||
|
description += "\n"
|
||||||
|
end
|
||||||
|
description += "Récupérer le formulaire vierge pour mon dossier : #{tpj.lien_demarche}"
|
||||||
|
end
|
||||||
|
TypeDeChamp.new(
|
||||||
|
libelle: tpj.libelle,
|
||||||
|
type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative),
|
||||||
|
description: description,
|
||||||
|
order_place: order_place,
|
||||||
|
mandatory: tpj.mandatory
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if types_de_champ.count > 1
|
||||||
|
types_de_champ
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -366,13 +366,12 @@ describe Procedure do
|
||||||
it 'should duplicate specific objects with different id' do
|
it 'should duplicate specific objects with different id' do
|
||||||
expect(subject.id).not_to eq(procedure.id)
|
expect(subject.id).not_to eq(procedure.id)
|
||||||
|
|
||||||
expect(subject.types_de_piece_justificative.size).to eq procedure.types_de_piece_justificative.size
|
expect(subject.types_de_champ.size).to eq(procedure.types_de_champ.size + 1 + procedure.types_de_piece_justificative.size)
|
||||||
expect(subject.types_de_champ.size).to eq procedure.types_de_champ.size
|
|
||||||
expect(subject.types_de_champ_private.size).to eq procedure.types_de_champ_private.size
|
expect(subject.types_de_champ_private.size).to eq procedure.types_de_champ_private.size
|
||||||
expect(subject.types_de_champ.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ.map(&:drop_down_list).compact.size
|
expect(subject.types_de_champ.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ.map(&:drop_down_list).compact.size
|
||||||
expect(subject.types_de_champ_private.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ_private.map(&:drop_down_list).compact.size
|
expect(subject.types_de_champ_private.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ_private.map(&:drop_down_list).compact.size
|
||||||
|
|
||||||
subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc|
|
procedure.types_de_champ.zip(subject.types_de_champ).each do |ptc, stc|
|
||||||
expect(stc).to have_same_attributes_as(ptc)
|
expect(stc).to have_same_attributes_as(ptc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -380,10 +379,6 @@ describe Procedure do
|
||||||
expect(stc).to have_same_attributes_as(ptc)
|
expect(stc).to have_same_attributes_as(ptc)
|
||||||
end
|
end
|
||||||
|
|
||||||
subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc|
|
|
||||||
expect(stc).to have_same_attributes_as(ptc)
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
||||||
|
|
||||||
expect(subject.cloned_from_library).to be(false)
|
expect(subject.cloned_from_library).to be(false)
|
||||||
|
@ -393,7 +388,18 @@ describe Procedure do
|
||||||
expect(cloned_procedure).to have_same_attributes_as(procedure)
|
expect(cloned_procedure).to have_same_attributes_as(procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the procedure is clone from the library' do
|
it 'should not clone piece justificatives but create corresponding champs' do
|
||||||
|
expect(subject.types_de_piece_justificative.size).to eq(0)
|
||||||
|
|
||||||
|
champs_pj = subject.types_de_champ[procedure.types_de_champ.size + 1, procedure.types_de_piece_justificative.size]
|
||||||
|
champs_pj.zip(procedure.types_de_piece_justificative).each do |stc, ptpj|
|
||||||
|
expect(stc.libelle).to eq(ptpj.libelle)
|
||||||
|
expect(stc.description).to eq(ptpj.description)
|
||||||
|
expect(stc.mandatory).to eq(ptpj.mandatory)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the procedure is cloned from the library' do
|
||||||
let(:from_library) { true }
|
let(:from_library) { true }
|
||||||
|
|
||||||
it { expect(subject.cloned_from_library).to be(true) }
|
it { expect(subject.cloned_from_library).to be(true) }
|
||||||
|
|
Loading…
Add table
Reference in a new issue