demarches-normaliennes/app/models/concerns/dossier_empty_concern.rb

30 lines
856 B
Ruby
Raw Normal View History

2024-10-22 10:55:40 +02:00
# frozen_string_literal: true
module DossierEmptyConcern
extend ActiveSupport::Concern
included do
scope :empty_brouillon, -> (created_at) do
dossiers_ids = Dossier.brouillon.where(created_at:).ids
dossiers_with_value = Dossier.select('id').includes(:champs)
.where.not(champs: { value: nil })
.where(id: dossiers_ids)
dossier_with_geo_areas = Dossier.select('id').includes(champs: :geo_areas)
.where.not(geo_areas: { id: nil })
.where(id: dossiers_ids)
dossier_with_pj = Dossier.select('id')
.joins(champs: :piece_justificative_file_attachments)
.where(id: dossiers_ids)
brouillon
.where.not(id: dossiers_with_value)
.where.not(id: dossier_with_geo_areas)
.where.not(id: dossier_with_pj)
.where(id: dossiers_ids)
end
end
end