diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 34b576c2f..e88d82a13 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -56,7 +56,7 @@ class ProcedureRevision < ApplicationRecord def find_or_clone_type_de_champ(id) type_de_champ = find_type_de_champ_by_id(id) - if type_de_champ.revision == self + if type_de_champ.only_present_on_draft? type_de_champ elsif type_de_champ.parent.present? find_or_clone_type_de_champ(type_de_champ.parent.stable_id).types_de_champ.find_by!(stable_id: id) @@ -88,7 +88,7 @@ class ProcedureRevision < ApplicationRecord def remove_type_de_champ(id) type_de_champ = find_type_de_champ_by_id(id) - if type_de_champ.revision == self + if type_de_champ.only_present_on_draft? type_de_champ.destroy elsif type_de_champ.parent.present? find_or_clone_type_de_champ(id).destroy diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 139e85f3c..5ec75a695 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -164,6 +164,10 @@ class TypeDeChamp < ApplicationRecord end end + def only_present_on_draft? + revisions.size == 1 + end + def non_fillable? type_champ.in?([ TypeDeChamp.type_champs.fetch(:header_section),