demarches-normaliennes/app/models/traitement.rb

29 lines
971 B
Ruby
Raw Normal View History

2020-08-06 16:35:45 +02:00
# == Schema Information
#
# Table name: traitements
#
# id :bigint not null, primary key
# instructeur_email :string
# motivation :string
# process_expired :boolean
# process_expired_migrated :boolean default(FALSE)
# processed_at :datetime
# state :string
# dossier_id :bigint
2020-08-06 16:35:45 +02:00
#
class Traitement < ApplicationRecord
belongs_to :dossier, optional: false
scope :en_construction, -> { where(state: Dossier.states.fetch(:en_construction)) }
scope :en_instruction, -> { where(state: Dossier.states.fetch(:en_instruction)) }
scope :termine, -> { where(state: Dossier::TERMINE) }
2021-06-16 15:13:36 +02:00
scope :for_traitement_time_stats, -> (procedure) do
includes(:dossier)
.termine
.where(dossier: procedure.dossiers.visible_by_administration)
.where.not('dossiers.depose_at' => nil, processed_at: nil)
.order(:processed_at)
end
end