Lod dossier operations

This commit is contained in:
Paul Chavard 2018-11-26 21:29:06 +01:00
parent 85e3eb04f4
commit 0f0ca2ec65
3 changed files with 23 additions and 9 deletions

View file

@ -81,7 +81,7 @@ module NewGestionnaire
end
def repasser_en_construction
dossier.repasser_en_construction!
dossier.repasser_en_construction!(current_gestionnaire)
flash.notice = 'Dossier repassé en construction.'
render partial: 'state_button_refresh', locals: { dossier: dossier }
@ -92,13 +92,13 @@ module NewGestionnaire
case params[:process_action]
when "refuser"
dossier.refuser!(motivation)
dossier.refuser!(current_gestionnaire, motivation)
flash.notice = "Dossier considéré comme refusé."
when "classer_sans_suite"
dossier.classer_sans_suite!(motivation)
dossier.classer_sans_suite!(current_gestionnaire, motivation)
flash.notice = "Dossier considéré comme sans suite."
when "accepter"
dossier.accepter!(motivation)
dossier.accepter!(current_gestionnaire, motivation)
flash.notice = "Dossier traité avec succès."
end

View file

@ -12,7 +12,7 @@ class AutoReceiveDossiersForProcedureJob < ApplicationJob
end
when Dossier.states.fetch(:accepte)
procedure.dossiers.state_en_construction.find_each do |dossier|
dossier.accepter!('')
dossier.accepter!(gestionnaire, '')
end
else
raise "Receiving Procedure##{procedure_id} in invalid state \"#{state}\""

View file

@ -311,14 +311,18 @@ class Dossier < ApplicationRecord
def passer_en_instruction!(gestionnaire)
en_instruction!
gestionnaire.follow(self)
log_dossier_operation(gestionnaire, :passer_en_instruction)
end
def repasser_en_construction!
def repasser_en_construction!(gestionnaire)
self.en_instruction_at = nil
en_construction!
log_dossier_operation(gestionnaire, :repasser_en_construction)
end
def accepter!(motivation)
def accepter!(gestionnaire, motivation)
self.motivation = motivation
self.en_instruction_at ||= Time.zone.now
@ -329,28 +333,38 @@ class Dossier < ApplicationRecord
end
NotificationMailer.send_closed_notification(self).deliver_later
log_dossier_operation(gestionnaire, :accepter)
end
def refuser!(motivation)
def refuser!(gestionnaire, motivation)
self.motivation = motivation
self.en_instruction_at ||= Time.zone.now
refuse!
NotificationMailer.send_refused_notification(self).deliver_later
log_dossier_operation(gestionnaire, :refuser)
end
def classer_sans_suite!(motivation)
def classer_sans_suite!(gestionnaire, motivation)
self.motivation = motivation
self.en_instruction_at ||= Time.zone.now
sans_suite!
NotificationMailer.send_without_continuation_notification(self).deliver_later
log_dossier_operation(gestionnaire, :classer_sans_suite)
end
private
def log_dossier_operation(gestionnaire, operation)
dossier_operation_logs.create(
gestionnaire: gestionnaire,
operation: DossierOperationLog.operations.fetch(operation)
)
end
def update_state_dates
if en_construction? && !self.en_construction_at
self.en_construction_at = Time.zone.now