From a2bd0582b958b7d1bffedd8bbfd0dc811aa49d91 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 17 Oct 2018 11:29:52 +0200 Subject: [PATCH 1/7] [Fix #2741] Filter / sort by en_construction_at --- app/models/procedure_presentation.rb | 1 + spec/models/procedure_presentation_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 1e55d8c13..03b75eefe 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -16,6 +16,7 @@ class ProcedurePresentation < ApplicationRecord def fields fields = [ field_hash('Créé le', 'self', 'created_at'), + field_hash('En construction le', 'self', 'en_construction_at'), field_hash('Mis à jour le', 'self', 'updated_at'), field_hash('Demandeur', 'user', 'email') ] diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index f85d9de97..d5a095fdd 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -58,6 +58,7 @@ describe ProcedurePresentation do let(:expected) { [ { "label" => 'Créé le', "table" => 'self', "column" => 'created_at' }, + { "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at' }, { "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at' }, { "label" => 'Demandeur', "table" => 'user', "column" => 'email' }, { "label" => 'SIREN', "table" => 'etablissement', "column" => 'entreprise_siren' }, From 37fb358bd5c8f3d8dd4125e7f6f74c988cfc78b7 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 17 Oct 2018 11:36:31 +0200 Subject: [PATCH 2/7] [#2741] Expand unit tests for #get_value just to be sure --- spec/models/procedure_presentation_spec.rb | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index d5a095fdd..218a87d7e 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -130,13 +130,29 @@ describe ProcedurePresentation do context 'for self table' do let(:table) { 'self' } - let(:column) { 'updated_at' } # All other columns work the same, no extra test required - let(:dossier) { create(:dossier, procedure: procedure) } + context 'for created_at column' do + let(:column) { 'created_at' } + let(:dossier) { Timecop.freeze(DateTime.new(1992, 3, 22)) { create(:dossier, procedure: procedure) } } - before { dossier.touch(time: DateTime.new(2018, 9, 25)) } + it { is_expected.to eq(DateTime.new(1992, 3, 22)) } + end - it { is_expected.to eq(DateTime.new(2018, 9, 25)) } + context 'for en_construction_at column' do + let(:column) { 'en_construction_at' } + let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } + + it { is_expected.to eq(DateTime.new(2018, 10, 17)) } + end + + context 'for updated_at column' do + let(:column) { 'updated_at' } + let(:dossier) { create(:dossier, procedure: procedure) } + + before { dossier.touch(time: DateTime.new(2018, 9, 25)) } + + it { is_expected.to eq(DateTime.new(2018, 9, 25)) } + end end context 'for user table' do From c652cf3ae5f41d74e0917610aabaed2ccf4c549b Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 17 Oct 2018 12:10:23 +0200 Subject: [PATCH 3/7] [#2741] Expand unit tests for sorted_ids just to be sure --- spec/models/procedure_presentation_spec.rb | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 218a87d7e..65e93dc79 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -257,18 +257,36 @@ describe ProcedurePresentation do context 'for self table' do let(:table) { 'self' } - let(:column) { 'updated_at' } # All other columns work the same, no extra test required let(:order) { 'asc' } # Desc works the same, no extra test required - let(:recent_dossier) { create(:dossier, procedure: procedure) } - let(:older_dossier) { create(:dossier, procedure: procedure) } + context 'for created_at column' do + let(:column) { 'created_at' } + let!(:recent_dossier) { Timecop.freeze(DateTime.new(2018, 10, 17)) { create(:dossier, procedure: procedure) } } + let!(:older_dossier) { Timecop.freeze(DateTime.new(2003, 11, 11)) { create(:dossier, procedure: procedure) } } - before do - recent_dossier.touch(time: DateTime.new(2018, 9, 25)) - older_dossier.touch(time: DateTime.new(2018, 5, 13)) + it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } end - it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } + context 'for en_construction_at column' do + let(:column) { 'en_construction_at' } + let!(:recent_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } + let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2013, 1, 1)) } + + it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } + end + + context 'for updated_at column' do + let(:column) { 'updated_at' } + let(:recent_dossier) { create(:dossier, procedure: procedure) } + let(:older_dossier) { create(:dossier, procedure: procedure) } + + before do + recent_dossier.touch(time: DateTime.new(2018, 9, 25)) + older_dossier.touch(time: DateTime.new(2018, 5, 13)) + end + + it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } + end end context 'for type_de_champ table' do From 0dea9f9ece9b88c4b62277f21d5688141dabeee1 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 17 Oct 2018 12:16:04 +0200 Subject: [PATCH 4/7] [#2741] Additional test to filtered_ids to be sure --- spec/models/procedure_presentation_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 65e93dc79..d4951f386 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -376,6 +376,14 @@ describe ProcedurePresentation do it { is_expected.to contain_exactly(kept_dossier.id) } end + context 'for en_construction_at column' do + let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } + let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2013, 1, 1)) } + let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018' }] } + + it { is_expected.to contain_exactly(kept_dossier.id) } + end + context 'for updated_at column' do let(:kept_dossier) { create(:dossier, procedure: procedure) } let(:discarded_dossier) { create(:dossier, procedure: procedure) } From f9d38762eaa3e6ac57cf907a8e8215fe8fc081a9 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 17 Oct 2018 12:02:16 +0200 Subject: [PATCH 5/7] [Ref #2738] Remove exercices from a soon-to-be deleted template --- app/views/dossiers/_infos_entreprise.html.haml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/views/dossiers/_infos_entreprise.html.haml b/app/views/dossiers/_infos_entreprise.html.haml index f07f3e90c..a4c5e6311 100644 --- a/app/views/dossiers/_infos_entreprise.html.haml +++ b/app/views/dossiers/_infos_entreprise.html.haml @@ -47,11 +47,7 @@ .row .col-xs-4.entreprise-label Exercices : .col-xs-8.entreprise-info - - @facade.etablissement.exercices.each_with_index do |exercice, index| - %strong - = "#{exercice.date_fin_exercice.year} : " - = number_to_currency(exercice.ca) - %br + les exercices comptables des trois dernières années sont joints à votre dossier. .row.split-row .col-xs-12.split-hr From da4037b2fd862c4b5f48f2daf854a93499b93f66 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 17 Oct 2018 12:02:24 +0200 Subject: [PATCH 6/7] Add a blank line --- app/views/shared/dossiers/_identite_entreprise.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/shared/dossiers/_identite_entreprise.html.haml b/app/views/shared/dossiers/_identite_entreprise.html.haml index 8dfe73487..11a4a1784 100644 --- a/app/views/shared/dossiers/_identite_entreprise.html.haml +++ b/app/views/shared/dossiers/_identite_entreprise.html.haml @@ -48,6 +48,7 @@ = "#{exercice.date_fin_exercice.year} : " = pretty_currency(exercice.ca) %br + - if etablissement.association? %tr %th.libelle Numéro RNA : From 3a973999a32b64678df35024b999b8c181e588cf Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 17 Oct 2018 12:12:32 +0200 Subject: [PATCH 7/7] [Ref #2738] Hide exercices if not gestionnaire --- app/views/new_gestionnaire/avis/show.html.haml | 2 +- app/views/new_gestionnaire/dossiers/print.html.haml | 4 ++-- app/views/new_gestionnaire/dossiers/show.html.haml | 2 +- app/views/new_user/dossiers/demande.html.haml | 2 +- app/views/shared/dossiers/_champs.html.haml | 2 +- app/views/shared/dossiers/_demande.html.haml | 4 ++-- .../shared/dossiers/_identite_entreprise.html.haml | 11 +++++++---- config/locales/models/siret/fr.yml | 3 +++ spec/views/shared/dossiers/_demande.html.haml_spec.rb | 2 +- .../dossiers/_identite_entreprise.html.haml_spec.rb | 2 +- 10 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/views/new_gestionnaire/avis/show.html.haml b/app/views/new_gestionnaire/avis/show.html.haml index 225e0c6f3..b2c53c6a8 100644 --- a/app/views/new_gestionnaire/avis/show.html.haml +++ b/app/views/new_gestionnaire/avis/show.html.haml @@ -2,4 +2,4 @@ = render partial: 'header', locals: { avis: @avis, dossier: @dossier } -= render partial: 'shared/dossiers/demande', locals: { dossier: @dossier, demande_seen_at: nil } += render partial: 'shared/dossiers/demande', locals: { dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' } diff --git a/app/views/new_gestionnaire/dossiers/print.html.haml b/app/views/new_gestionnaire/dossiers/print.html.haml index 4e0c5e62f..3bf327b69 100644 --- a/app/views/new_gestionnaire/dossiers/print.html.haml +++ b/app/views/new_gestionnaire/dossiers/print.html.haml @@ -6,7 +6,7 @@ = render partial: "shared/dossiers/user_infos", locals: { user: @dossier.user } - if @dossier.etablissement.present? - = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: @dossier.etablissement } + = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: @dossier.etablissement, profile: 'instructeur' } - if @dossier.individual.present? = render partial: "shared/dossiers/identite_individual", locals: { individual: @dossier.individual } @@ -15,7 +15,7 @@ - champs = @dossier.champs.decorate - if champs.any? - = render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil } + = render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' } - if @dossier.procedure.use_api_carto %h3 Cartographie diff --git a/app/views/new_gestionnaire/dossiers/show.html.haml b/app/views/new_gestionnaire/dossiers/show.html.haml index 694aea923..cb5a2a4a3 100644 --- a/app/views/new_gestionnaire/dossiers/show.html.haml +++ b/app/views/new_gestionnaire/dossiers/show.html.haml @@ -2,4 +2,4 @@ = render partial: "header", locals: { dossier: @dossier } -= render partial: "shared/dossiers/demande", locals: { dossier: @dossier, demande_seen_at: @demande_seen_at } += render partial: "shared/dossiers/demande", locals: { dossier: @dossier, demande_seen_at: @demande_seen_at, profile: 'instructeur' } diff --git a/app/views/new_user/dossiers/demande.html.haml b/app/views/new_user/dossiers/demande.html.haml index 623a8ac54..b29f8db7f 100644 --- a/app/views/new_user/dossiers/demande.html.haml +++ b/app/views/new_user/dossiers/demande.html.haml @@ -6,7 +6,7 @@ #dossier-show = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } - = render partial: 'shared/dossiers/demande', locals: { dossier: @dossier, demande_seen_at: nil } + = render partial: 'shared/dossiers/demande', locals: { dossier: @dossier, demande_seen_at: nil, profile: 'usager' } .container - if !@dossier.read_only? diff --git a/app/views/shared/dossiers/_champs.html.haml b/app/views/shared/dossiers/_champs.html.haml index ca2cc3025..eee34dde3 100644 --- a/app/views/shared/dossiers/_champs.html.haml +++ b/app/views/shared/dossiers/_champs.html.haml @@ -55,7 +55,7 @@ %td.rich-text %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } - if c.etablissement.present? - = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: c.etablissement } + = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: c.etablissement, profile: profile } - else %th.libelle = "#{c.libelle} :" diff --git a/app/views/shared/dossiers/_demande.html.haml b/app/views/shared/dossiers/_demande.html.haml index e5595e499..9e7e572af 100644 --- a/app/views/shared/dossiers/_demande.html.haml +++ b/app/views/shared/dossiers/_demande.html.haml @@ -4,7 +4,7 @@ = render partial: "shared/dossiers/user_infos", locals: { user: dossier.user } - if dossier.etablissement.present? - = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: dossier.etablissement } + = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: dossier.etablissement, profile: profile } - if dossier.individual.present? = render partial: "shared/dossiers/identite_individual", locals: { individual: dossier.individual } @@ -13,7 +13,7 @@ - champs = dossier.champs.includes(:type_de_champ).decorate - if champs.any? .card - = render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at } + = render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile } - if dossier.procedure.use_api_carto .tab-title Cartographie diff --git a/app/views/shared/dossiers/_identite_entreprise.html.haml b/app/views/shared/dossiers/_identite_entreprise.html.haml index 11a4a1784..87be8390f 100644 --- a/app/views/shared/dossiers/_identite_entreprise.html.haml +++ b/app/views/shared/dossiers/_identite_entreprise.html.haml @@ -44,10 +44,13 @@ %tr %th.libelle Exercices : %td - - etablissement.exercices.each_with_index do |exercice, index| - = "#{exercice.date_fin_exercice.year} : " - = pretty_currency(exercice.ca) - %br + - if profile == 'instructeur' + - etablissement.exercices.each_with_index do |exercice, index| + = "#{exercice.date_fin_exercice.year} : " + = pretty_currency(exercice.ca) + %br + - elsif etablissement.exercices.present? + = t('activemodel.models.exercices_summary', count: etablissement.exercices.count) - if etablissement.association? %tr diff --git a/config/locales/models/siret/fr.yml b/config/locales/models/siret/fr.yml index 1a62a04d5..4e54f43c3 100644 --- a/config/locales/models/siret/fr.yml +++ b/config/locales/models/siret/fr.yml @@ -2,6 +2,9 @@ fr: activemodel: models: siret: 'SIRET' + exercices_summary: + one: L’exercice comptable de l’année dernière a été joint à votre dossier. + other: "Les exercices comptables des %{count} dernières années ont été joints à votre dossier." errors: models: siret: diff --git a/spec/views/shared/dossiers/_demande.html.haml_spec.rb b/spec/views/shared/dossiers/_demande.html.haml_spec.rb index d8c507fce..7cbfddb54 100644 --- a/spec/views/shared/dossiers/_demande.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_demande.html.haml_spec.rb @@ -9,7 +9,7 @@ describe 'shared/dossiers/demande.html.haml', type: :view do sign_in current_gestionnaire end - subject! { render 'shared/dossiers/demande.html.haml', dossier: dossier, demande_seen_at: nil } + subject! { render 'shared/dossiers/demande.html.haml', dossier: dossier, demande_seen_at: nil, profile: 'usager' } context 'when dossier was created by an etablissement' do let(:etablissement) { create(:etablissement) } diff --git a/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb b/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb index f80e4eee8..91189a6e2 100644 --- a/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb @@ -1,5 +1,5 @@ describe 'shared/dossiers/identite_entreprise.html.haml', type: :view do - before { render 'shared/dossiers/identite_entreprise.html.haml', etablissement: etablissement } + before { render 'shared/dossiers/identite_entreprise.html.haml', etablissement: etablissement, profile: 'usager' } context "there is an association" do let(:etablissement) { create(:etablissement, :is_association) }