fix(spec): get back to stable state

This commit is contained in:
Martin 2021-11-19 12:36:03 +01:00
parent 646459a1da
commit 1d721f14a0
2 changed files with 20 additions and 1 deletions

View file

@ -304,10 +304,21 @@ class Dossier < ApplicationRecord
.joins(:procedure) .joins(:procedure)
.where("dossiers.en_instruction_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) .where("dossiers.en_instruction_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end end
# TODO/MFO
# maybe reconsider `termine_close_to_expiration` implementation, but for now this implementation is missing
# 1. the check on traitements.processed_at? -> is is replicated on dossier?
# 2. the check on process_expired
# scope :termine_close_to_expiration, -> do
# state_termine
# .joins(:procedure)
# .where("dossiers.processed_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
# end
# TODO/MFO
scope :termine_close_to_expiration, -> do scope :termine_close_to_expiration, -> do
state_termine state_termine
.joins(:procedure) .joins(:procedure)
.where("dossiers.processed_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) .where(id: Traitement.termine_close_to_expiration.select(:dossier_id).distinct)
end end
scope :brouillon_expired, -> do scope :brouillon_expired, -> do

View file

@ -25,6 +25,14 @@ class Traitement < ApplicationRecord
.order(:processed_at) .order(:processed_at)
end end
scope :termine_close_to_expiration, -> do
joins(dossier: :procedure)
.termine
.where(process_expired: true)
.where('dossiers.state' => Dossier::TERMINE)
.where("traitements.processed_at + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: Dossier::INTERVAL_BEFORE_EXPIRATION })
end
def self.count_dossiers_termines_by_month(groupe_instructeurs) def self.count_dossiers_termines_by_month(groupe_instructeurs)
last_traitements_per_dossier = Traitement last_traitements_per_dossier = Traitement
.select('max(traitements.processed_at) as processed_at') .select('max(traitements.processed_at) as processed_at')