fix(sva): improvements when a dossier has already been terminated
This commit is contained in:
parent
70b57257eb
commit
b5e2c9b860
7 changed files with 133 additions and 21 deletions
|
@ -26,11 +26,13 @@ class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
||||||
class_names(
|
class_names(
|
||||||
'fr-badge fr-badge--sm': true,
|
'fr-badge fr-badge--sm': true,
|
||||||
'fr-badge--warning': soon?,
|
'fr-badge--warning': soon?,
|
||||||
'fr-badge--info': !soon?
|
'fr-badge--info': !without_date? && !soon?
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def soon?
|
def soon?
|
||||||
|
return false if object.sva_svr_decision_on.nil?
|
||||||
|
|
||||||
object.sva_svr_decision_on < 7.days.from_now.to_date
|
object.sva_svr_decision_on < 7.days.from_now.to_date
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,16 +53,36 @@ class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_for_badge
|
def label_for_badge
|
||||||
sva? ? "SVA :" : "SVR :"
|
"#{human_decision} : "
|
||||||
end
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
return if without_date?
|
if previously_termine?
|
||||||
|
t('.previously_termine_title')
|
||||||
if pending_correction?
|
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)
|
t(".dossier_terminated_x_days_after_correction", count: days_count)
|
||||||
else
|
else
|
||||||
t(".dossier_terminated_on", date: helpers.l(object.sva_svr_decision_on))
|
t(".dossier_terminated_on", date: helpers.l(object.sva_svr_decision_on))
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
---
|
---
|
||||||
en:
|
en:
|
||||||
no_sva: Submitted before SVA
|
manual_decision: Manual instruction
|
||||||
no_svr: Submitted before SVR
|
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:
|
in_days:
|
||||||
zero: Today
|
zero: Today
|
||||||
one: Tomorrow
|
one: Tomorrow
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
---
|
---
|
||||||
fr:
|
fr:
|
||||||
no_sva: Déposé avant SVA
|
manual_decision: Instruction manuelle
|
||||||
no_svr: Déposé avant SVR
|
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:
|
in_days:
|
||||||
zero: Aujourd’hui
|
zero: Aujourd’hui
|
||||||
one: Demain
|
one: Demain
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
- if without_date?
|
%span{ class: classes, title: title }
|
||||||
%span.fr-badge.fr-badge--sm
|
- if with_label.present?
|
||||||
= t(sva? ? '.no_sva' : '.no_svr')
|
= label_for_badge
|
||||||
- else
|
|
||||||
%span{ class: classes, title: title }
|
- if previously_termine?
|
||||||
- if with_label.present?
|
= t('.manual_decision')
|
||||||
= label_for_badge
|
- elsif depose_before_configuration?
|
||||||
- if pending_correction?
|
= t('.depose_before_configuration', decision: human_decision)
|
||||||
= t('.remaining_days_after_correction', count: days_count)
|
- elsif without_date? # generic case without SVA/SVR date, when we have a projection
|
||||||
- else
|
= t('.manual_decision')
|
||||||
= t('.in_days', count: days_count)
|
- elsif pending_correction?
|
||||||
|
= t('.remaining_days_after_correction', count: days_count)
|
||||||
|
- else
|
||||||
|
= t('.in_days', count: days_count)
|
||||||
|
|
|
@ -942,6 +942,7 @@ class Dossier < ApplicationRecord
|
||||||
.processed_at
|
.processed_at
|
||||||
attestation&.destroy
|
attestation&.destroy
|
||||||
|
|
||||||
|
self.sva_svr_decision_on = nil
|
||||||
self.motivation = nil
|
self.motivation = nil
|
||||||
self.justificatif_motivation.purge_later
|
self.justificatif_motivation.purge_later
|
||||||
|
|
||||||
|
@ -1089,6 +1090,10 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def previously_termine?
|
||||||
|
traitements.termine.exists?
|
||||||
|
end
|
||||||
|
|
||||||
def remove_titres_identite!
|
def remove_titres_identite!
|
||||||
champs_public.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
champs_public.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -1494,7 +1494,7 @@ describe Dossier, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#repasser_en_instruction!' do
|
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!(:instructeur) { create(:instructeur) }
|
||||||
let(:last_operation) { dossier.dossier_operation_logs.last }
|
let(:last_operation) { dossier.dossier_operation_logs.last }
|
||||||
|
|
||||||
|
@ -1512,6 +1512,7 @@ describe Dossier, type: :model do
|
||||||
it { expect(dossier.motivation).to be_nil }
|
it { expect(dossier.motivation).to be_nil }
|
||||||
it { expect(dossier.justificatif_motivation.attached?).to be_falsey }
|
it { expect(dossier.justificatif_motivation.attached?).to be_falsey }
|
||||||
it { expect(dossier.attestation).to be_nil }
|
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(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.operation).to eq('repasser_en_instruction') }
|
||||||
it { expect(last_operation.data['author']['email']).to eq(instructeur.email) }
|
it { expect(last_operation.data['author']['email']).to eq(instructeur.email) }
|
||||||
|
|
Loading…
Reference in a new issue