fix(revisions): fix repetitions export with revisions

This commit is contained in:
Paul Chavard 2021-10-22 12:18:43 +02:00 committed by Paul Chavard
parent 39c94992a7
commit f6b8689a97
10 changed files with 78 additions and 57 deletions

View file

@ -99,20 +99,16 @@ class Procedure < ApplicationRecord
end
def types_de_champ_for_procedure_presentation
explanatory_types_de_champ = [:header_section, :explication, :repetition].map { |k| TypeDeChamp.type_champs.fetch(k) }
if brouillon?
TypeDeChamp
.joins(:revisions)
.where.not(type_champ: explanatory_types_de_champ)
.where(procedure_revisions: { id: draft_revision_id })
TypeDeChamp.fillable
.joins(:revision_types_de_champ)
.where(revision_types_de_champ: { revision: draft_revision })
.order(:private, :position)
else
# fetch all type_de_champ.stable_id for all the revisions expect draft
# and for each stable_id take the bigger (more recent) type_de_champ.id
recent_ids = TypeDeChamp
recent_ids = TypeDeChamp.fillable
.joins(:revisions)
.where.not(type_champ: explanatory_types_de_champ)
.where(procedure_revisions: { procedure_id: id })
.where.not(procedure_revisions: { id: draft_revision_id })
.group(:stable_id)
@ -139,6 +135,7 @@ class Procedure < ApplicationRecord
else
TypeDeChamp.root
.public_only
.fillable
.where(revision: revisions - [draft_revision])
.order(:created_at)
.uniq
@ -151,6 +148,7 @@ class Procedure < ApplicationRecord
else
TypeDeChamp.root
.private_only
.fillable
.where(revision: revisions - [draft_revision])
.order(:created_at)
.uniq