From c5174f7d43dae36e8afc55dae4ae241940b54bb5 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 15 Feb 2024 16:43:31 +0100 Subject: [PATCH] feat(attestation): dossier for preview priorize termine dossier: all data are available --- app/models/procedure.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e14f29d34..88106acfa 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -995,8 +995,9 @@ class Procedure < ApplicationRecord def dossier_for_preview(user) # Try to use a preview or a dossier filled by current user dossiers.where(for_procedure_preview: true).or(dossiers.not_brouillon) - .order(Arel.sql("CASE WHEN for_procedure_preview = True THEN 1 ELSE 0 END DESC, - CASE WHEN user_id = #{user.id} THEN 1 ELSE 0 END DESC")) \ + .order(Arel.sql("CASE WHEN user_id = #{user.id} THEN 1 ELSE 0 END DESC, + CASE WHEN state = 'accepte' THEN 1 ELSE 0 END DESC, + CASE WHEN for_procedure_preview = True THEN 1 ELSE 0 END DESC")) \ .first end