diff --git a/app/models/concerns/dossier_filtering_concern.rb b/app/models/concerns/dossier_filtering_concern.rb index 58bcff54b..c4bc53c18 100644 --- a/app/models/concerns/dossier_filtering_concern.rb +++ b/app/models/concerns/dossier_filtering_concern.rb @@ -4,9 +4,16 @@ module DossierFilteringConcern included do scope :filter_by_datetimes, lambda { |column, dates| if dates.present? - dates - .map { |date| self.where(column => date..(date + 1.day)) } - .reduce(:or) + case column + when 'depose_since' + where('dossiers.depose_at >= ?', dates.sort.first) + when 'updated_since' + where('dossiers.updated_at >= ?', dates.sort.first) + else + dates + .map { |date| self.where(column => date..(date + 1.day)) } + .reduce(:or) + end else none end diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 1d95e9e27..1685bf800 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -41,6 +41,8 @@ class ProcedurePresentation < ApplicationRecord field_hash('self', 'en_construction_at'), field_hash('self', 'depose_at'), field_hash('self', 'updated_at'), + field_hash('self', 'depose_since'), + field_hash('self', 'updated_since'), field_hash('user', 'email'), field_hash('followers_instructeurs', 'email'), field_hash('groupe_instructeur', 'label') diff --git a/config/locales/models/procedure_presentation/en.yml b/config/locales/models/procedure_presentation/en.yml index 35d370029..55dbe127a 100644 --- a/config/locales/models/procedure_presentation/en.yml +++ b/config/locales/models/procedure_presentation/en.yml @@ -10,6 +10,8 @@ en: en_construction_at: En construction le depose_at: Submitted on updated_at: Updated on + depose_since: Submitted since + updated_since: Updated since user: email: Requester followers_instructeurs: diff --git a/config/locales/models/procedure_presentation/fr.yml b/config/locales/models/procedure_presentation/fr.yml index 6fe01d80c..fb6a1155a 100644 --- a/config/locales/models/procedure_presentation/fr.yml +++ b/config/locales/models/procedure_presentation/fr.yml @@ -10,6 +10,8 @@ fr: en_construction_at: En construction le depose_at: Déposé le updated_at: Mis à jour le + depose_since: Déposé depuis + updated_since: Mis à jour depuis user: email: Demandeur followers_instructeurs: diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 86c85f8b8..b92c3a773 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -62,6 +62,8 @@ describe ProcedurePresentation do { "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at', 'classname' => '' }, { "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at', 'classname' => '' }, { "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at', 'classname' => '' }, + { "label" => "Déposé depuis", "table" => "self", "column" => "depose_since", "classname" => "" }, + { "label" => "Mis à jour depuis", "table" => "self", "column" => "updated_since", "classname" => "" }, { "label" => 'Demandeur', "table" => 'user', "column" => 'email', 'classname' => '' }, { "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email', 'classname' => '' }, { "label" => 'Groupe instructeur', "table" => 'groupe_instructeur', "column" => 'label', 'classname' => '' }, @@ -415,6 +417,22 @@ describe ProcedurePresentation do it { is_expected.to contain_exactly(kept_dossier.id) } end + context 'for updated_since column' do + let(:filter) { [{ 'table' => 'self', 'column' => 'updated_since', 'value' => '18/9/2018' }] } + + let(:kept_dossier) { create(:dossier, procedure: procedure) } + let(:later_dossier) { create(:dossier, procedure: procedure) } + let(:discarded_dossier) { create(:dossier, procedure: procedure) } + + before do + kept_dossier.touch(time: Time.zone.local(2018, 9, 18, 14, 28)) + later_dossier.touch(time: Time.zone.local(2018, 9, 19, 14, 28)) + discarded_dossier.touch(time: Time.zone.local(2018, 9, 17, 14, 28)) + end + + it { is_expected.to match_array([kept_dossier.id, later_dossier.id]) } + end + context 'ignore time of day' do let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018 19:30' }] }