Merge pull request #7109 from betagouv/US/fix-counter-including-discarded-procedures
ETQ instructeur, les compteurs entre la synthese et les procedures ne sont pas synchro
This commit is contained in:
commit
c21eac0513
3 changed files with 23 additions and 4 deletions
|
@ -12,7 +12,9 @@ module Instructeurs
|
|||
.includes(:defaut_groupe_instructeur)
|
||||
.order(closed_at: :desc, unpublished_at: :desc, published_at: :desc, created_at: :desc)
|
||||
|
||||
dossiers = current_instructeur.dossiers.joins(:groupe_instructeur)
|
||||
dossiers = current_instructeur.dossiers
|
||||
.joins(groupe_instructeur: :procedure)
|
||||
.where(procedures: { hidden_at: nil })
|
||||
dossiers_visibles = dossiers.visible_by_administration
|
||||
@dossiers_count_per_procedure = dossiers_visibles.all_state.group('groupe_instructeurs.procedure_id').reorder(nil).count
|
||||
@dossiers_a_suivre_count_per_procedure = dossiers_visibles.without_followers.en_cours.group('groupe_instructeurs.procedure_id').reorder(nil).count
|
||||
|
|
|
@ -301,18 +301,18 @@ class Dossier < ApplicationRecord
|
|||
scope :interval_brouillon_close_to_expiration, -> do
|
||||
state_brouillon
|
||||
.visible_by_user
|
||||
.where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
.where("dossiers.created_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
end
|
||||
scope :interval_en_construction_close_to_expiration, -> do
|
||||
state_en_construction
|
||||
.visible_by_user_or_administration
|
||||
.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
.where("dossiers.en_construction_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
end
|
||||
scope :interval_termine_close_to_expiration, -> do
|
||||
state_termine
|
||||
.visible_by_user_or_administration
|
||||
.where(procedures: { procedure_expires_when_termine_enabled: true })
|
||||
.where("dossiers.processed_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
.where("dossiers.processed_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
end
|
||||
|
||||
scope :brouillon_close_to_expiration, -> do
|
||||
|
|
|
@ -155,6 +155,23 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(1 + 0) }
|
||||
it { expect(assigns(:all_dossiers_counts)['expirant']).to eq(2 + 0) }
|
||||
end
|
||||
|
||||
context 'with not draft state on discarded procedure' do
|
||||
let(:discarded_procedure) { create(:procedure, :discarded, :expirable) }
|
||||
let(:state) { Dossier.states.fetch(:en_construction) }
|
||||
before do
|
||||
create(:dossier, procedure: discarded_procedure, state: Dossier.states.fetch(:en_construction))
|
||||
instructeur.groupe_instructeurs << discarded_procedure.defaut_groupe_instructeur
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(1) }
|
||||
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(1) }
|
||||
|
||||
it { expect(assigns(:dossiers_count_per_procedure)[discarded_procedure.id]).to be_nil }
|
||||
|
||||
it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(1) }
|
||||
end
|
||||
end
|
||||
|
||||
context "with a routed procedure" do
|
||||
|
|
Loading…
Add table
Reference in a new issue