[#1110] Motivation and date de décision are only tags for terminé dossiers
This commit is contained in:
parent
e985439416
commit
ab63f80080
2 changed files with 44 additions and 8 deletions
|
@ -1,18 +1,27 @@
|
||||||
module TagsSubstitutionConcern
|
module TagsSubstitutionConcern
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def tags
|
def tags(is_dossier_termine: true)
|
||||||
if procedure.for_individual?
|
if procedure.for_individual?
|
||||||
identity_tags = individual_tags
|
identity_tags = individual_tags
|
||||||
else
|
else
|
||||||
identity_tags = entreprise_tags + etablissement_tags
|
identity_tags = entreprise_tags + etablissement_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
identity_tags + dossier_tags + procedure_type_de_champ_public_private_tags
|
tags = identity_tags + dossier_tags + procedure_type_de_champ_public_private_tags
|
||||||
|
filter_tags(tags, is_dossier_termine)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def filter_tags(tags, is_dossier_termine)
|
||||||
|
if !is_dossier_termine
|
||||||
|
tags.reject { |tag| tag[:dossier_termine_only] }
|
||||||
|
else
|
||||||
|
tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def procedure_type_de_champ_public_private_tags
|
def procedure_type_de_champ_public_private_tags
|
||||||
(procedure.types_de_champ + procedure.types_de_champ_private)
|
(procedure.types_de_champ + procedure.types_de_champ_private)
|
||||||
.map { |tdc| { libelle: tdc.libelle, description: tdc.description } }
|
.map { |tdc| { libelle: tdc.libelle, description: tdc.description } }
|
||||||
|
@ -21,10 +30,12 @@ module TagsSubstitutionConcern
|
||||||
def dossier_tags
|
def dossier_tags
|
||||||
[{ libelle: 'motivation',
|
[{ libelle: 'motivation',
|
||||||
description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite',
|
description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite',
|
||||||
target: :motivation },
|
target: :motivation,
|
||||||
|
dossier_termine_only: true },
|
||||||
{ libelle: 'date de décision',
|
{ libelle: 'date de décision',
|
||||||
description: 'Date de la décision d’acceptation, refus, ou classement sans suite',
|
description: 'Date de la décision d’acceptation, refus, ou classement sans suite',
|
||||||
lambda: -> (d) { d.processed_at.present? ? d.processed_at.localtime.strftime('%d/%m/%Y') : '' } },
|
lambda: -> (d) { d.processed_at.present? ? d.processed_at.localtime.strftime('%d/%m/%Y') : '' },
|
||||||
|
dossier_termine_only: true },
|
||||||
{ libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } },
|
{ libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } },
|
||||||
{ libelle: 'numéro du dossier', description: '', target: :id }]
|
{ libelle: 'numéro du dossier', description: '', target: :id }]
|
||||||
end
|
end
|
||||||
|
@ -60,7 +71,9 @@ module TagsSubstitutionConcern
|
||||||
[entreprise_tags, dossier.entreprise],
|
[entreprise_tags, dossier.entreprise],
|
||||||
[etablissement_tags, dossier.entreprise&.etablissement]]
|
[etablissement_tags, dossier.entreprise&.etablissement]]
|
||||||
|
|
||||||
tags_and_datas.inject(text) { |acc, (tags, data)| replace_tags_with_values_from_data(acc, tags, data) }
|
tags_and_datas
|
||||||
|
.map { |(tags, data)| [filter_tags(tags, dossier.termine?), data] }
|
||||||
|
.inject(text) { |acc, (tags, data)| replace_tags_with_values_from_data(acc, tags, data) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_type_de_champ_tags(text, types_de_champ, dossier_champs)
|
def replace_type_de_champ_tags(text, types_de_champ, dossier_champs)
|
||||||
|
|
|
@ -117,6 +117,8 @@ describe TagsSubstitutionConcern, type: :model do
|
||||||
context 'when the dossier has a motivation' do
|
context 'when the dossier has a motivation' do
|
||||||
let(:dossier) { create(:dossier, motivation: 'motivation') }
|
let(:dossier) { create(:dossier, motivation: 'motivation') }
|
||||||
|
|
||||||
|
before { dossier.accepte! }
|
||||||
|
|
||||||
context 'and the template has some dossier tags' do
|
context 'and the template has some dossier tags' do
|
||||||
let(:template) { '--motivation-- --numéro du dossier--' }
|
let(:template) { '--motivation-- --numéro du dossier--' }
|
||||||
|
|
||||||
|
@ -208,11 +210,32 @@ describe TagsSubstitutionConcern, type: :model do
|
||||||
it_behaves_like "treat all kinds of space as equivalent"
|
it_behaves_like "treat all kinds of space as equivalent"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when generating a document for a dossier that is not termine' do
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
let(:template) { '--motivation-- --date de décision--' }
|
||||||
|
|
||||||
|
subject { template_concern.replace_tags(template, dossier) }
|
||||||
|
|
||||||
|
it "does not treat motivation or date de décision as tags" do
|
||||||
|
is_expected.to eq('--motivation-- --date de décision--')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'tags' do
|
describe 'tags' do
|
||||||
|
context 'when generating a document for a dossier terminé' do
|
||||||
subject { template_concern.tags }
|
subject { template_concern.tags }
|
||||||
|
|
||||||
|
it { is_expected.to include(include({ libelle: 'motivation' })) }
|
||||||
it { is_expected.to include(include({ libelle: 'date de décision' })) }
|
it { is_expected.to include(include({ libelle: 'date de décision' })) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when generating a document for a dossier that is not terminé' do
|
||||||
|
subject { template_concern.tags(is_dossier_termine: false) }
|
||||||
|
|
||||||
|
it { is_expected.not_to include(include({ libelle: 'motivation' })) }
|
||||||
|
it { is_expected.not_to include(include({ libelle: 'date de décision' })) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue