From 935a38bde0063f680c61d96494816c88902982ea Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 9 Jan 2018 11:10:56 +0100 Subject: [PATCH 1/2] [#1037] Introduce `format-date` function --- app/models/concerns/tags_substitution_concern.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 932276b1d..ddc302fce 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -34,12 +34,20 @@ module TagsSubstitutionConcern dossier_termine_only: true }, { libelle: 'date de décision', 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) { format_date(d.processed_at) }, dossier_termine_only: true }, { libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } }, { libelle: 'numéro du dossier', description: '', target: :id }] end + def format_date(date) + if date.present? + date.localtime.strftime('%d/%m/%Y') + else + '' + end + end + def individual_tags [{ libelle: 'civilité', description: 'M., Mme', target: :gender }, { libelle: 'nom', description: "nom de l'usager", target: :nom }, From 7f040a5cf841811b9122250d2e55e7ef3b0c55b9 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 9 Jan 2018 11:15:35 +0100 Subject: [PATCH 2/2] [Fix #1037] Add date tags to mail / attestation templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - date de dépôt - date de passage en instruction --- .../concerns/tags_substitution_concern.rb | 6 +++++ .../concern/tags_substitution_concern_spec.rb | 27 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index ddc302fce..b224e7f46 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -32,6 +32,12 @@ module TagsSubstitutionConcern description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite', target: :motivation, dossier_termine_only: true }, + { libelle: 'date de dépôt', + description: 'Date du passage en construction du dossier par l’usager', + lambda: -> (d) { format_date(d.en_construction_at) } }, + { libelle: 'date de passage en instruction', + description: '', + lambda: -> (d) { format_date(d.en_instruction_at) } }, { libelle: 'date de décision', description: 'Date de la décision d’acceptation, refus, ou classement sans suite', lambda: -> (d) { format_date(d.processed_at) }, diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 99c3aeea1..6ab217926 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -167,12 +167,31 @@ describe TagsSubstitutionConcern, type: :model do end end - context "when the template has a date de décision tag" do - let(:template) { '--date de décision--' } + context "when using a date tag" do + before do + dossier.accepte! + dossier.en_construction_at = DateTime.new(2001, 2, 3) + dossier.en_instruction_at = DateTime.new(2004, 5, 6) + dossier.processed_at = DateTime.new(2007, 8, 9) + end - before { dossier.accepte! } + context "with date de dépôt" do + let(:template) { '--date de dépôt--' } - it { is_expected.to eq(DateTime.now.localtime.strftime('%d/%m/%Y')) } + it { is_expected.to eq('03/02/2001') } + end + + context "with date de passage en instruction" do + let(:template) { '--date de passage en instruction--' } + + it { is_expected.to eq('06/05/2004') } + end + + context "with date de décision" do + let(:template) { '--date de décision--' } + + it { is_expected.to eq('09/08/2007') } + end end context "when the template has a libellé procédure tag" do