feat(instructeur#dossiers_count_summary): add counter for expirants. ignore brouillon
This commit is contained in:
parent
ce87878ff0
commit
2dfbc70d41
3 changed files with 47 additions and 4 deletions
|
@ -53,7 +53,7 @@ module Instructeurs
|
|||
|
||||
@a_suivre_count, @suivis_count, @traites_count, @tous_count, @archives_count = current_instructeur
|
||||
.dossiers_count_summary(groupe_instructeur_ids)
|
||||
.fetch_values('a_suivre', 'suivis', 'traites', 'tous', 'archives')
|
||||
.fetch_values('a_suivre', 'suivis', 'traites', 'tous', 'archives', 'expirant')
|
||||
|
||||
dossiers_visibles = Dossier
|
||||
.where(groupe_instructeur_id: groupe_instructeur_ids)
|
||||
|
@ -72,6 +72,7 @@ module Instructeurs
|
|||
@termines_dossiers = dossiers_visibles.termine
|
||||
@all_state_dossiers = dossiers_visibles.all_state
|
||||
@archived_dossiers = dossiers_visibles.archived
|
||||
@expirant_dossiers = dossiers_visibles.close_to_expiration
|
||||
|
||||
@dossiers = case statut
|
||||
when 'a-suivre'
|
||||
|
@ -89,6 +90,9 @@ module Instructeurs
|
|||
when 'archives'
|
||||
dossiers_count = @archives_count
|
||||
@archived_dossiers
|
||||
when 'expirant'
|
||||
dossiers_count = @archives_count
|
||||
@expirant_dossiers
|
||||
end
|
||||
|
||||
notifications = current_instructeur.notifications_for_groupe_instructeurs(groupe_instructeur_ids)
|
||||
|
|
|
@ -237,8 +237,22 @@ class Instructeur < ApplicationRecord
|
|||
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.instructeur_id = :instructeur_id) AS suivis,
|
||||
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND dossiers.state in ('accepte', 'refuse', 'sans_suite')) AS traites,
|
||||
COUNT(DISTINCT dossiers.id) FILTER (where not archived) AS tous,
|
||||
COUNT(DISTINCT dossiers.id) FILTER (where archived) AS archives
|
||||
COUNT(DISTINCT dossiers.id) FILTER (where archived) AS archives,
|
||||
COUNT(DISTINCT dossiers.id) FILTER (where
|
||||
procedures.procedure_expires_when_termine_enabled
|
||||
AND (
|
||||
dossiers.state in ('accepte', 'refuse', 'sans_suite')
|
||||
AND dossiers.processed_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now
|
||||
) OR (
|
||||
dossiers.state in ('en_construction')
|
||||
AND dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now
|
||||
)
|
||||
) AS expirant
|
||||
FROM "dossiers"
|
||||
INNER JOIN "procedure_revisions"
|
||||
ON "procedure_revisions"."id" = "dossiers"."revision_id"
|
||||
INNER JOIN "procedures"
|
||||
ON "procedures"."id" = "procedure_revisions"."procedure_id"
|
||||
LEFT OUTER JOIN follows
|
||||
ON follows.dossier_id = dossiers.id
|
||||
AND follows.unfollowed_at IS NULL
|
||||
|
@ -250,7 +264,9 @@ class Instructeur < ApplicationRecord
|
|||
sanitized_query = ActiveRecord::Base.sanitize_sql([
|
||||
query,
|
||||
instructeur_id: id,
|
||||
groupe_instructeur_ids: groupe_instructeur_ids
|
||||
groupe_instructeur_ids: groupe_instructeur_ids,
|
||||
now: Time.zone.now,
|
||||
expires_in: Dossier::INTERVAL_BEFORE_EXPIRATION
|
||||
])
|
||||
|
||||
Dossier.connection.select_all(sanitized_query).first
|
||||
|
|
|
@ -594,7 +594,7 @@ describe Instructeur, type: :model do
|
|||
describe "#dossiers_count_summary" do
|
||||
let(:instructeur_2) { create(:instructeur) }
|
||||
let(:instructeur_3) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, instructeurs: [instructeur_2, instructeur_3]) }
|
||||
let(:procedure) { create(:procedure, instructeurs: [instructeur_2, instructeur_3], procedure_expires_when_termine_enabled: true) }
|
||||
let(:gi_1) { procedure.groupe_instructeurs.first }
|
||||
let(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
|
||||
let(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
|
||||
|
@ -614,6 +614,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(0) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
end
|
||||
|
||||
context 'with a new brouillon dossier' do
|
||||
|
@ -624,6 +625,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(0) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
end
|
||||
|
||||
context 'with a new dossier without follower' do
|
||||
|
@ -634,6 +636,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(1) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
|
||||
context 'and dossiers without follower on each of the others groups' do
|
||||
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
||||
|
@ -658,6 +661,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(1) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
|
||||
context 'and another one follows the same dossier' do
|
||||
before do
|
||||
|
@ -669,6 +673,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(1) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
end
|
||||
|
||||
context 'and dossier with a follower on each of the others groups' do
|
||||
|
@ -692,6 +697,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['a_suivre']).to eq(1) }
|
||||
it { expect(subject['suivis']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(1) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -703,6 +709,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(1) }
|
||||
it { expect(subject['tous']).to eq(1) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
|
||||
context 'and terminer dossiers on each of the others groups' do
|
||||
let!(:termine_dossier_on_gi_2) { create(:dossier, :accepte, groupe_instructeur: gi_2) }
|
||||
|
@ -715,6 +722,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(2) }
|
||||
it { expect(subject['tous']).to eq(2) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -726,6 +734,7 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['traites']).to eq(0) }
|
||||
it { expect(subject['tous']).to eq(0) }
|
||||
it { expect(subject['archives']).to eq(1) }
|
||||
it { expect(subject['expirant']).to eq(0) }
|
||||
|
||||
context 'and terminer dossiers on each of the others groups' do
|
||||
let!(:archives_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2, archived: true) }
|
||||
|
@ -734,6 +743,20 @@ describe Instructeur, type: :model do
|
|||
it { expect(subject['archives']).to eq(2) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an expirants dossier' do
|
||||
let!(:expiring_dossier_termine) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago) }
|
||||
let!(:expiring_dossier_en_construction) { create(:dossier, :en_construction, en_construction_at: 175.days.ago, procedure: procedure) }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { expect(subject['a_suivre']).to eq(1) }
|
||||
it { expect(subject['suivis']).to eq(0) }
|
||||
it { expect(subject['traites']).to eq(1) }
|
||||
it { expect(subject['tous']).to eq(2) }
|
||||
it { expect(subject['archives']).to eq(0) }
|
||||
it { expect(subject['expirant']).to eq(2) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue