diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 6c36aa7be..7b0d52996 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -160,7 +160,7 @@ module Users end def submit_brouillon - @dossier = dossier_with_champs + @dossier = dossier_with_champs(pj_template: false) errors = submit_dossier_and_compute_errors if errors.blank? @@ -209,7 +209,7 @@ module Users end def update - @dossier = dossier_with_champs + @dossier = dossier_with_champs(pj_template: false) errors = update_dossier_and_compute_errors if errors.present? @@ -409,8 +409,8 @@ module Users end end - def dossier_with_champs - DossierPreloader.load_one(dossier) + def dossier_with_champs(pj_template: true) + DossierPreloader.load_one(dossier, pj_template:) end def should_change_groupe_instructeur? diff --git a/app/models/champ.rb b/app/models/champ.rb index 6cf371393..e5c1a72b1 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -198,7 +198,7 @@ class Champ < ApplicationRecord end def conditional? - type_de_champ.condition.present? + type_de_champ.read_attribute_before_type_cast('condition').present? end def visible? diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 8e1d0f113..3d4a0ac2a 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -17,8 +17,8 @@ class DossierPreloader dossiers end - def self.load_one(dossier) - DossierPreloader.new([dossier]).all(pj_template: true).first + def self.load_one(dossier, pj_template: false) + DossierPreloader.new([dossier]).all(pj_template: pj_template).first end private diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index 70db5a24b..07d26af01 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -29,15 +29,16 @@ class Logic::ChampValue < Logic::Term return nil if !targeted_champ.visible? return nil if targeted_champ.blank? - case type_de_champ(champs.map(&:type_de_champ)).type_champ - when MANAGED_TYPE_DE_CHAMP.fetch(:yes_no), - MANAGED_TYPE_DE_CHAMP.fetch(:checkbox) + # on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type + case targeted_champ.type + when "Champs::YesNoChamp", + "Champs::CheckboxChamp" targeted_champ.true? - when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number) + when "Champs::IntegerNumberChamp", "Champs::DecimalNumberChamp" targeted_champ.for_api - when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list) + when "Champs::DropDownListChamp" targeted_champ.selected - when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list) + when "Champs::MultipleDropDownListChamp" targeted_champ.selected_options end end diff --git a/spec/models/dossier_preloader_spec.rb b/spec/models/dossier_preloader_spec.rb index f1de07b97..b2bcba549 100644 --- a/spec/models/dossier_preloader_spec.rb +++ b/spec/models/dossier_preloader_spec.rb @@ -11,7 +11,7 @@ describe DossierPreloader do let(:first_child) { subject.champs.second.champs.first } describe 'all' do - subject { DossierPreloader.load_one(dossier) } + subject { DossierPreloader.load_one(dossier, pj_template: true) } before { subject }