diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index ecfa8e778..81774fb7b 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -226,14 +226,10 @@ module Users errors = submit_dossier_and_compute_errors if errors.blank? + pending_correction_confirm = cast_bool(params.dig(:dossier, :pending_correction_confirm)) editing_fork_origin = @dossier.editing_fork_origin editing_fork_origin.merge_fork(@dossier) - RoutingEngine.compute(editing_fork_origin) - - if cast_bool(params.dig(:dossier, :pending_correction_confirm)) - editing_fork_origin.resolve_pending_correction! - editing_fork_origin.process_sva_svr! - end + editing_fork_origin.submit_en_construction!(pending_correction_confirm:) redirect_to dossier_path(editing_fork_origin) else diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 3538116a7..8714a8343 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -120,6 +120,10 @@ class Dossier < ApplicationRecord processed_at: processed_at) end + def submit_en_construction(processed_at: Time.zone.now) + build(state: Dossier.states.fetch(:en_construction), processed_at:) + end + def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now) build(state: Dossier.states.fetch(:en_instruction), instructeur_email: instructeur&.email, @@ -908,6 +912,18 @@ class Dossier < ApplicationRecord RoutingEngine.compute(self) end + def submit_en_construction!(pending_correction_confirm: false) + self.traitements.submit_en_construction + save! + + RoutingEngine.compute(self) + + if pending_correction_confirm + resolve_pending_correction! + process_sva_svr! + end + end + def after_passer_en_instruction(h) instructeur = h[:instructeur] disable_notification = h.fetch(:disable_notification, false)