use traitement model
when a dossier is terminated (accepte, refuse or classe_sans_suite), we store now `processed_at` and `motivation` in a traitement instance
This commit is contained in:
parent
f631acd118
commit
a072d35211
14 changed files with 107 additions and 29 deletions
|
@ -42,6 +42,7 @@ class Dossier < ApplicationRecord
|
|||
has_many :followers_instructeurs, through: :follows, source: :instructeur
|
||||
has_many :previous_followers_instructeurs, -> { distinct }, through: :previous_follows, source: :instructeur
|
||||
has_many :avis, inverse_of: :dossier, dependent: :destroy
|
||||
has_many :traitements, -> { order(:processed_at) }, inverse_of: :dossier, dependent: :destroy
|
||||
|
||||
has_many :dossier_operation_logs, -> { order(:created_at) }, dependent: :nullify, inverse_of: :dossier
|
||||
|
||||
|
@ -293,6 +294,16 @@ class Dossier < ApplicationRecord
|
|||
validates :individual, presence: true, if: -> { procedure.for_individual? }
|
||||
validates :groupe_instructeur, presence: true
|
||||
|
||||
def motivation
|
||||
return nil if !termine?
|
||||
traitements.any? ? traitements.last.motivation : read_attribute(:motivation)
|
||||
end
|
||||
|
||||
def processed_at
|
||||
return nil if !termine?
|
||||
traitements.any? ? traitements.last.processed_at : read_attribute(:processed_at)
|
||||
end
|
||||
|
||||
def update_search_terms
|
||||
self.search_terms = [
|
||||
user&.email,
|
||||
|
@ -529,8 +540,6 @@ class Dossier < ApplicationRecord
|
|||
|
||||
def after_repasser_en_instruction(instructeur)
|
||||
self.archived = false
|
||||
self.processed_at = nil
|
||||
self.motivation = nil
|
||||
self.en_instruction_at = Time.zone.now
|
||||
attestation&.destroy
|
||||
|
||||
|
@ -540,14 +549,12 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def after_accepter(instructeur, motivation, justificatif = nil)
|
||||
self.motivation = motivation
|
||||
self.traitements.build(state: Dossier.states.fetch(:accepte), instructeur: instructeur, motivation: motivation, processed_at: Time.zone.now)
|
||||
|
||||
if justificatif
|
||||
self.justificatif_motivation.attach(justificatif)
|
||||
end
|
||||
|
||||
self.processed_at = Time.zone.now
|
||||
|
||||
if attestation.nil?
|
||||
self.attestation = build_attestation
|
||||
end
|
||||
|
@ -558,39 +565,37 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def after_accepter_automatiquement
|
||||
self.traitements.build(state: Dossier.states.fetch(:accepte), instructeur: nil, motivation: nil, processed_at: Time.zone.now)
|
||||
self.en_instruction_at ||= Time.zone.now
|
||||
|
||||
if attestation.nil?
|
||||
self.attestation = build_attestation
|
||||
end
|
||||
|
||||
self.processed_at = Time.zone.now
|
||||
save!
|
||||
NotificationMailer.send_closed_notification(self).deliver_later
|
||||
log_automatic_dossier_operation(:accepter, self)
|
||||
end
|
||||
|
||||
def after_refuser(instructeur, motivation, justificatif = nil)
|
||||
self.motivation = motivation
|
||||
self.traitements.build(state: Dossier.states.fetch(:refuse), instructeur: instructeur, motivation: motivation, processed_at: Time.zone.now)
|
||||
|
||||
if justificatif
|
||||
self.justificatif_motivation.attach(justificatif)
|
||||
end
|
||||
|
||||
self.processed_at = Time.zone.now
|
||||
save!
|
||||
NotificationMailer.send_refused_notification(self).deliver_later
|
||||
log_dossier_operation(instructeur, :refuser, self)
|
||||
end
|
||||
|
||||
def after_classer_sans_suite(instructeur, motivation, justificatif = nil)
|
||||
self.motivation = motivation
|
||||
self.traitements.build(state: Dossier.states.fetch(:sans_suite), instructeur: instructeur, motivation: motivation, processed_at: Time.zone.now)
|
||||
|
||||
if justificatif
|
||||
self.justificatif_motivation.attach(justificatif)
|
||||
end
|
||||
|
||||
self.processed_at = Time.zone.now
|
||||
save!
|
||||
NotificationMailer.send_without_continuation_notification(self).deliver_later
|
||||
log_dossier_operation(instructeur, :classer_sans_suite, self)
|
||||
|
|
|
@ -161,7 +161,7 @@ class Instructeur < ApplicationRecord
|
|||
h = {
|
||||
nb_en_construction: groupe.dossiers.en_construction.count,
|
||||
nb_en_instruction: groupe.dossiers.en_instruction.count,
|
||||
nb_accepted: groupe.dossiers.accepte.where(processed_at: Time.zone.yesterday.beginning_of_day..Time.zone.yesterday.end_of_day).count,
|
||||
nb_accepted: Traitement.where(dossier: groupe.dossiers.accepte, processed_at: Time.zone.yesterday.beginning_of_day..Time.zone.yesterday.end_of_day).count,
|
||||
nb_notification: notifications_for_procedure(procedure, :not_archived).count
|
||||
}
|
||||
|
||||
|
|
4
app/models/traitement.rb
Normal file
4
app/models/traitement.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class Traitement < ApplicationRecord
|
||||
belongs_to :dossier
|
||||
belongs_to :instructeur
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue