refactor(correction): preload corrections for exports
This commit is contained in:
parent
6b908ffb27
commit
c95f4ab700
2 changed files with 8 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -481,6 +481,7 @@ class Dossier < ApplicationRecord
|
|||
:traitement,
|
||||
:groupe_instructeur,
|
||||
:etablissement,
|
||||
:pending_corrections,
|
||||
procedure: [:groupe_instructeurs],
|
||||
avis: [:claimant, :expert]
|
||||
).ordered_for_export).in_batches
|
||||
|
|
Loading…
Add table
Reference in a new issue