From 6b908ffb270d8e7b58a5e60b834d2e46d6cfe2c2 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 3 Jul 2023 09:53:17 +0200 Subject: [PATCH 1/2] feat(correction): correction sub-state + date in pdf --- app/views/dossiers/show.pdf.prawn | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index a6586981f..9fe2b31e0 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -223,7 +223,8 @@ end def add_etat_dossier(pdf, dossier) pdf.pad_bottom(default_margin) do - pdf.text "Ce dossier est #{clean_string(dossier_display_state(dossier, lower: true))}.", inline_format: true + pending_correction = dossier.pending_correction? ? " (en attente de correction)" : nil + pdf.text "Ce dossier est #{clean_string(dossier_display_state(dossier, lower: true))}#{pending_correction}.", inline_format: true end end @@ -231,9 +232,15 @@ def add_etats_dossier(pdf, dossier) if dossier.depose_at.present? format_in_2_columns(pdf, "Déposé le", try_format_date(dossier.depose_at)) end + + if dossier.pending_correction? + format_in_2_columns(pdf, "Correction demandée le", try_format_date(dossier.pending_correction.created_at)) + end + if dossier.en_instruction_at.present? format_in_2_columns(pdf, "En instruction le", try_format_date(dossier.en_instruction_at)) end + if dossier.processed_at.present? format_in_2_columns(pdf, "Décision le", try_format_date(dossier.processed_at)) end From c95f4ab7002f7574167157a28a4e9be058c62d9e Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 28 Jun 2023 18:57:32 +0200 Subject: [PATCH 2/2] refactor(correction): preload corrections for exports --- app/models/concerns/dossier_correctable_concern.rb | 11 +++++++---- app/models/dossier.rb | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/dossier_correctable_concern.rb b/app/models/concerns/dossier_correctable_concern.rb index 721d19a76..7669d0164 100644 --- a/app/models/concerns/dossier_correctable_concern.rb +++ b/app/models/concerns/dossier_correctable_concern.rb @@ -4,6 +4,7 @@ module DossierCorrectableConcern included do A_CORRIGER = 'a_corriger' has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy + has_many :pending_corrections, -> { DossierCorrection.pending }, class_name: 'DossierCorrection', inverse_of: :dossier scope :with_pending_corrections, -> { joins(:corrections).where(corrections: { resolved_at: nil }) } @@ -18,7 +19,7 @@ module DossierCorrectableConcern end def may_flag_as_pending_correction? - return false if corrections.pending.exists? + return false if pending_corrections.exists? en_construction? || may_repasser_en_construction? end @@ -27,15 +28,17 @@ module DossierCorrectableConcern # We don't want to show any alert if user is not allowed to modify the dossier return false unless en_construction? - corrections.pending.exists? + return pending_corrections.any? if pending_corrections.loaded? + + pending_corrections.exists? end def pending_correction - corrections.pending.first + pending_corrections.first end def resolve_pending_correction! - corrections.pending.update!(resolved_at: Time.current) + pending_corrections.update!(resolved_at: Time.current) end end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5337e9215..46789f0df 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -481,6 +481,7 @@ class Dossier < ApplicationRecord :traitement, :groupe_instructeur, :etablissement, + :pending_corrections, procedure: [:groupe_instructeurs], avis: [:claimant, :expert] ).ordered_for_export).in_batches