From ffef1a644cfa38e5e209a28a18d3b909c4db5f3b Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 17 May 2018 15:32:36 +0200 Subject: [PATCH] procedure_path should check for test and regular procedure --- app/dashboards/procedure_dashboard.rb | 1 - app/models/procedure.rb | 6 ++++-- app/models/procedure_path.rb | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index 87eff4600..dc7c3681d 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -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, diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 1a6e41566..bae4d72f3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -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) diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index bfe75ef04..5b6ca20c2 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -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