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, types_de_champ: TypesDeChampCollectionField,
path: ProcedureLinkField, path: ProcedureLinkField,
dossiers: Field::HasMany, dossiers: Field::HasMany,
procedure_path: Field::HasOne,
administrateur: Field::BelongsTo, administrateur: Field::BelongsTo,
id: Field::Number, id: Field::Number,
libelle: Field::String, 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 :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy
has_many :dossiers has_many :dossiers
has_one :procedure_path, dependent: :destroy
has_one :module_api_carto, dependent: :destroy has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, 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) Dossier.new(procedure: self, champs: champs, champs_private: champs_private)
end end
def procedure_path
ProcedurePath.find_with_procedure(self)
end
def hide! def hide!
now = DateTime.now now = DateTime.now
self.update(hidden_at: now, aasm_state: :hidden) 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 :test_procedure, class_name: 'Procedure'
belongs_to :procedure belongs_to :procedure
belongs_to :administrateur belongs_to :administrateur
def self.find_with_procedure(procedure)
where(procedure: procedure).or(where(test_procedure: procedure)).last
end
end end