feat(routing): use only department codes in routing rules
This commit is contained in:
parent
4e6788919f
commit
ca25788f07
6 changed files with 22 additions and 21 deletions
|
@ -70,6 +70,6 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def departements_for_select
|
def departements_for_select
|
||||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", constant("#{_1[:code]} – #{_1[:name]}").to_json] }
|
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", constant(_1[:code]).to_json] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,19 +40,26 @@ module Administrateurs
|
||||||
|
|
||||||
tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
|
tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
|
||||||
|
|
||||||
tdc_options = case tdc.type_champ
|
case tdc.type_champ
|
||||||
when TypeDeChamp.type_champs.fetch(:departements)
|
when TypeDeChamp.type_champs.fetch(:departements)
|
||||||
tdc.codes_and_names
|
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
tdc_options.each do |code_and_name, code|
|
||||||
tdc.drop_down_options.reject(&:empty?)
|
routing_rule = ds_eq(champ_value(stable_id), constant(code))
|
||||||
end
|
@procedure
|
||||||
|
.groupe_instructeurs
|
||||||
|
.find_or_create_by(label: code_and_name)
|
||||||
|
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
|
||||||
|
end
|
||||||
|
|
||||||
tdc_options.each do |option_label|
|
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||||
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
|
tdc_options = tdc.drop_down_options.reject(&:empty?)
|
||||||
@procedure
|
tdc_options.each do |option_label|
|
||||||
.groupe_instructeurs
|
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
|
||||||
.find_or_create_by(label: option_label)
|
@procedure
|
||||||
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
|
.groupe_instructeurs
|
||||||
|
.find_or_create_by(label: option_label)
|
||||||
|
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if tdc.drop_down_other?
|
if tdc.drop_down_other?
|
||||||
|
|
|
@ -108,7 +108,7 @@ class GroupeInstructeur < ApplicationRecord
|
||||||
|
|
||||||
options = case routing_tdc.type_champ
|
options = case routing_tdc.type_champ
|
||||||
when TypeDeChamp.type_champs.fetch(:departements)
|
when TypeDeChamp.type_champs.fetch(:departements)
|
||||||
routing_tdc.codes_and_names
|
APIGeoService.departements.map { _1[:code] }
|
||||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||||
routing_tdc.options_with_drop_down_other
|
routing_tdc.options_with_drop_down_other
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
when "Champs::MultipleDropDownListChamp"
|
when "Champs::MultipleDropDownListChamp"
|
||||||
targeted_champ.selected_options
|
targeted_champ.selected_options
|
||||||
when "Champs::DepartementChamp"
|
when "Champs::DepartementChamp"
|
||||||
targeted_champ.to_s
|
targeted_champ.code
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -477,12 +477,6 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def codes_and_names
|
|
||||||
if departement?
|
|
||||||
APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# historicaly we added a blank ("") option by default to avoid wrong selection
|
# historicaly we added a blank ("") option by default to avoid wrong selection
|
||||||
# see self.parse_drop_down_list_value
|
# see self.parse_drop_down_list_value
|
||||||
# then rails decided to add this blank ("") option when the select is required
|
# then rails decided to add this blank ("") option when the select is required
|
||||||
|
|
|
@ -74,7 +74,7 @@ describe RoutingEngine, type: :model do
|
||||||
|
|
||||||
context 'with a matching rule' do
|
context 'with a matching rule' do
|
||||||
before do
|
before do
|
||||||
gi_2.update(routing_rule: ds_eq(champ_value(departements_tdc.stable_id), constant('43 – Haute-Loire')))
|
gi_2.update(routing_rule: ds_eq(champ_value(departements_tdc.stable_id), constant('43')))
|
||||||
dossier.champs.first.update(value: 'Haute-Loire')
|
dossier.champs.first.update(value: 'Haute-Loire')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue