Merge pull request #9260 from colinux/export-corrections

ETQ instructeur: intègre les demandes de corrections dans les PDF
This commit is contained in:
Colin Darie 2023-07-04 09:58:07 +00:00 committed by GitHub
commit dfbb824dde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View file

@ -4,6 +4,7 @@ module DossierCorrectableConcern
included do included do
A_CORRIGER = 'a_corriger' A_CORRIGER = 'a_corriger'
has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy 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 }) } scope :with_pending_corrections, -> { joins(:corrections).where(corrections: { resolved_at: nil }) }
@ -18,7 +19,7 @@ module DossierCorrectableConcern
end end
def may_flag_as_pending_correction? def may_flag_as_pending_correction?
return false if corrections.pending.exists? return false if pending_corrections.exists?
en_construction? || may_repasser_en_construction? en_construction? || may_repasser_en_construction?
end end
@ -27,15 +28,17 @@ module DossierCorrectableConcern
# We don't want to show any alert if user is not allowed to modify the dossier # We don't want to show any alert if user is not allowed to modify the dossier
return false unless en_construction? return false unless en_construction?
corrections.pending.exists? return pending_corrections.any? if pending_corrections.loaded?
pending_corrections.exists?
end end
def pending_correction def pending_correction
corrections.pending.first pending_corrections.first
end end
def resolve_pending_correction! def resolve_pending_correction!
corrections.pending.update!(resolved_at: Time.current) pending_corrections.update!(resolved_at: Time.current)
end end
end end
end end

View file

@ -483,6 +483,7 @@ class Dossier < ApplicationRecord
:traitement, :traitement,
:groupe_instructeur, :groupe_instructeur,
:etablissement, :etablissement,
:pending_corrections,
procedure: [:groupe_instructeurs], procedure: [:groupe_instructeurs],
avis: [:claimant, :expert] avis: [:claimant, :expert]
).ordered_for_export).in_batches ).ordered_for_export).in_batches

View file

@ -223,7 +223,8 @@ end
def add_etat_dossier(pdf, dossier) def add_etat_dossier(pdf, dossier)
pdf.pad_bottom(default_margin) do pdf.pad_bottom(default_margin) do
pdf.text "Ce dossier est <b>#{clean_string(dossier_display_state(dossier, lower: true))}</b>.", inline_format: true pending_correction = dossier.pending_correction? ? " (en attente de correction)" : nil
pdf.text "Ce dossier est <b>#{clean_string(dossier_display_state(dossier, lower: true))}#{pending_correction}</b>.", inline_format: true
end end
end end
@ -231,9 +232,15 @@ def add_etats_dossier(pdf, dossier)
if dossier.depose_at.present? if dossier.depose_at.present?
format_in_2_columns(pdf, "Déposé le", try_format_date(dossier.depose_at)) format_in_2_columns(pdf, "Déposé le", try_format_date(dossier.depose_at))
end 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? if dossier.en_instruction_at.present?
format_in_2_columns(pdf, "En instruction le", try_format_date(dossier.en_instruction_at)) format_in_2_columns(pdf, "En instruction le", try_format_date(dossier.en_instruction_at))
end end
if dossier.processed_at.present? if dossier.processed_at.present?
format_in_2_columns(pdf, "Décision le", try_format_date(dossier.processed_at)) format_in_2_columns(pdf, "Décision le", try_format_date(dossier.processed_at))
end end