add average_dossier_weight
Co-authored-by: Christophe Robillard <christophe.robillard@beta.gouv.fr>
This commit is contained in:
parent
7002811ba5
commit
9e43823f9a
1 changed files with 13 additions and 0 deletions
|
@ -688,6 +688,19 @@ class Procedure < ApplicationRecord
|
|||
draft_revision.deep_clone(include: [:revision_types_de_champ, :revision_types_de_champ_private])
|
||||
end
|
||||
|
||||
def average_dossier_weight
|
||||
if dossiers.termine.any?
|
||||
total_size = Champ
|
||||
.includes(piece_justificative_file_attachment: :blob)
|
||||
.where(type: "Champs::PieceJustificativeChamp", dossier: dossiers.termine.limit(100))
|
||||
.sum('active_storage_blobs.byte_size')
|
||||
|
||||
total_size / dossiers.termine.limit(100).count
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def before_publish
|
||||
|
|
Loading…
Add table
Reference in a new issue