[#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
|
||||
procedure = self.deep_clone(include:
|
||||
{
|
||||
types_de_piece_justificative: nil,
|
||||
attestation_template: nil,
|
||||
types_de_champ: :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) }
|
||||
|
||||
procedure.types_de_champ += PiecesJustificativesService.types_pj_as_types_de_champ(self)
|
||||
procedure.administrateur = admin
|
||||
procedure.initiated_mail = initiated_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." }
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue