Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ instructeur d'une démarche SVA/SVR je visualise mieux un dossier terminé qui est repassé en instruction #9450

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions app/components/instructeurs/sva_svr_decision_badge_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def classes
class_names(
'fr-badge fr-badge--sm': true,
'fr-badge--warning': soon?,
'fr-badge--info': !soon?
'fr-badge--info': !without_date? && !soon?
)
end

def soon?
return false if object.sva_svr_decision_on.nil?

object.sva_svr_decision_on < 7.days.from_now.to_date
end

Expand All @@ -51,16 +53,36 @@ def svr?
end

def label_for_badge
sva? ? "SVA :" : "SVR :"
"#{human_decision} : "
end

def title
return if without_date?

if pending_correction?
if previously_termine?
t('.previously_termine_title')
elsif depose_before_configuration?
t('.depose_before_configuration_title', decision: human_decision)
elsif without_date?
t('.manual_decision_title', decision: human_decision)
elsif pending_correction?
t(".dossier_terminated_x_days_after_correction", count: days_count)
else
t(".dossier_terminated_on", date: helpers.l(object.sva_svr_decision_on))
end
end

def human_decision
procedure.sva_svr_configuration.human_decision
end

def previously_termine?
return if !object.respond_to?(:previously_termine?)

object.previously_termine?
end

def depose_before_configuration?
return if !object.respond_to?(:sva_svr_decision_triggered_at)

object.sva_svr_decision_on.nil? && object.sva_svr_decision_triggered_at.nil?
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
en:
no_sva: Submitted before SVA
no_svr: Submitted before SVR
manual_decision: Manual instruction
manual_decision_title: The file must be processed by an instructor, either because it was submitted before the %{decision} configuration, or because it has been returned to the instruction stage.
depose_before_configuration: Submitted before %{decision}
depose_before_configuration_title: This file was submitted before the %{decision} configuration.
previously_termine_title: The file has been returned to the instruction stage. It must now be processed by an instructor.
in_days:
zero: Today
one: Tomorrow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
fr:
no_sva: Déposé avant SVA
no_svr: Déposé avant SVR
manual_decision: Instruction manuelle
manual_decision_title: Le dossier doit être traité par un instructeur, soit car il a été déposé avant la configuration %{decision}, soit car il a été repassé en instruction.
depose_before_configuration: Déposé avant %{decision}
depose_before_configuration_title: Ce dossier a été déposé avant la configuration %{decision}.
previously_termine_title: Le dossier a été repassé en instruction. Il doit être traité par un instructeur.
in_days:
zero: Aujourd’hui
one: Demain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
- if without_date?
%span.fr-badge.fr-badge--sm
= t(sva? ? '.no_sva' : '.no_svr')
- else
%span{ class: classes, title: title }
- if with_label.present?
= label_for_badge
- if pending_correction?
= t('.remaining_days_after_correction', count: days_count)
- else
= t('.in_days', count: days_count)
%span{ class: classes, title: title }
- if with_label.present?
= label_for_badge

- if previously_termine?
= t('.manual_decision')
- elsif depose_before_configuration?
= t('.depose_before_configuration', decision: human_decision)
- elsif without_date? # generic case without SVA/SVR date, when we have a projection
= t('.manual_decision')
- elsif pending_correction?
= t('.remaining_days_after_correction', count: days_count)
- else
= t('.in_days', count: days_count)
5 changes: 5 additions & 0 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ def after_repasser_en_instruction(h)
.processed_at
attestation&.destroy

self.sva_svr_decision_on = nil
self.motivation = nil
self.justificatif_motivation.purge_later

Expand Down Expand Up @@ -1089,6 +1090,10 @@ def process_sva_svr!
end
end

def previously_termine?
traitements.termine.exists?
end

def remove_titres_identite!
champs_public.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

RSpec.describe Instructeurs::SVASVRDecisionBadgeComponent, type: :component do
let(:procedure) { create(:procedure, sva_svr: { decision: :sva, period: 10, unit: :days, resume: :continue }) }
let(:with_label) { false }

before do
travel_to DateTime.new(2023, 9, 1)
end

context 'with dossier object' do
subject do
render_inline(described_class.new(projection_or_dossier: dossier, procedure:, with_label:))
end

let(:title) { subject.at_css("span")["title"] }

context 'dossier en instruction' do
let(:dossier) { create(:dossier, :en_instruction, procedure:, sva_svr_decision_on: Date.new(2023, 9, 5)) }
it { expect(subject).to have_text("dans 4 jours") }
it { expect(title).to have_text("sera automatiquement traité le 05/09/2023") }

context 'with label' do
let(:with_label) { true }
it { expect(subject.text.delete("\n")).to have_text("SVA : dans 4 jours") }
end
end

context 'without sva date' do
let(:dossier) { create(:dossier, :en_instruction, procedure:) }

context 'dossier depose before configuration' do
it { expect(subject).to have_text("Déposé avant SVA") }
it { expect(title).to have_text("avant la configuration SVA") }
end

context 'dossier previously terminated' do
before {
create(:traitement, :accepte, dossier:)
}

it { expect(subject).to have_text("Instruction manuelle") }
it { expect(title).to have_text("repassé en instruction") }
end
end

context 'pending corrections' do
let(:dossier) { create(:dossier, :en_construction, procedure:, depose_at: Time.current, sva_svr_decision_on: Date.new(2023, 9, 5)) }

before do
create(:dossier_correction, dossier:)
end

it { expect(subject).to have_text("4 j. après correction") }
end
end

context 'with projection object' do
subject do
render_inline(described_class.new(projection_or_dossier: projection, procedure:, with_label:))
end

context 'dossier en instruction' do
let(:projection) { DossierProjectionService::DossierProjection.new(dossier_id: 12, state: :en_instruction, sva_svr_decision_on: Date.new(2023, 9, 5)) }

it { expect(subject).to have_text("dans 4 jours") }
end

context 'dossier without sva decision date' do
let(:projection) { DossierProjectionService::DossierProjection.new(dossier_id: 12, state: :en_instruction) }

it { expect(subject).to have_text("Instruction manuelle") }
end
end
end
3 changes: 2 additions & 1 deletion spec/models/dossier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@
end

describe '#repasser_en_instruction!' do
let(:dossier) { create(:dossier, :refuse, :with_attestation, :with_justificatif, archived: true, termine_close_to_expiration_notice_sent_at: Time.zone.now) }
let(:dossier) { create(:dossier, :refuse, :with_attestation, :with_justificatif, archived: true, termine_close_to_expiration_notice_sent_at: Time.zone.now, sva_svr_decision_on: 1.day.ago) }
let!(:instructeur) { create(:instructeur) }
let(:last_operation) { dossier.dossier_operation_logs.last }

Expand All @@ -1512,6 +1512,7 @@
it { expect(dossier.motivation).to be_nil }
it { expect(dossier.justificatif_motivation.attached?).to be_falsey }
it { expect(dossier.attestation).to be_nil }
it { expect(dossier.sva_svr_decision_on).to be_nil }
it { expect(dossier.termine_close_to_expiration_notice_sent_at).to be_nil }
it { expect(last_operation.operation).to eq('repasser_en_instruction') }
it { expect(last_operation.data['author']['email']).to eq(instructeur.email) }
Expand Down