procedure_path should check for test and regular procedure

This commit is contained in:
Paul Chavard 2018-05-17 15:32:36 +02:00
parent 4ad3932c05
commit ffef1a644c
3 changed files with 8 additions and 3 deletions

View file

@ -12,7 +12,6 @@ class ProcedureDashboard < Administrate::BaseDashboard
types_de_champ: TypesDeChampCollectionField,
path: ProcedureLinkField,
dossiers: Field::HasMany,
procedure_path: Field::HasOne,
administrateur: Field::BelongsTo,
id: Field::Number,
libelle: Field::String,

View file

@ -4,8 +4,6 @@ class Procedure < ApplicationRecord
has_many :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy
has_many :dossiers
has_one :procedure_path, dependent: :destroy
has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy
@ -61,6 +59,10 @@ class Procedure < ApplicationRecord
Dossier.new(procedure: self, champs: champs, champs_private: champs_private)
end
def procedure_path
ProcedurePath.find_with_procedure(self)
end
def hide!
now = DateTime.now
self.update(hidden_at: now, aasm_state: :hidden)

View file

@ -6,4 +6,8 @@ class ProcedurePath < ApplicationRecord
belongs_to :test_procedure, class_name: 'Procedure'
belongs_to :procedure
belongs_to :administrateur
def self.find_with_procedure(procedure)
where(procedure: procedure).or(where(test_procedure: procedure)).last
end
end