feat(routing): use only department codes in routing rules

This commit is contained in:
Eric Leroy-Terquem 2023-08-29 11:35:39 +02:00
parent 4e6788919f
commit ca25788f07
6 changed files with 22 additions and 21 deletions

View file

@ -70,6 +70,6 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
end
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

View file

@ -40,19 +40,26 @@ module Administrateurs
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)
tdc.codes_and_names
when TypeDeChamp.type_champs.fetch(:drop_down_list)
tdc.drop_down_options.reject(&:empty?)
end
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
tdc_options.each do |code_and_name, code|
routing_rule = ds_eq(champ_value(stable_id), constant(code))
@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|
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
@procedure
.groupe_instructeurs
.find_or_create_by(label: option_label)
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
when TypeDeChamp.type_champs.fetch(:drop_down_list)
tdc_options = tdc.drop_down_options.reject(&:empty?)
tdc_options.each do |option_label|
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
@procedure
.groupe_instructeurs
.find_or_create_by(label: option_label)
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
end
end
if tdc.drop_down_other?

View file

@ -108,7 +108,7 @@ class GroupeInstructeur < ApplicationRecord
options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
routing_tdc.codes_and_names
APIGeoService.departements.map { _1[:code] }
when TypeDeChamp.type_champs.fetch(:drop_down_list)
routing_tdc.options_with_drop_down_other
end

View file

@ -45,7 +45,7 @@ class Logic::ChampValue < Logic::Term
when "Champs::MultipleDropDownListChamp"
targeted_champ.selected_options
when "Champs::DepartementChamp"
targeted_champ.to_s
targeted_champ.code
end
end

View file

@ -477,12 +477,6 @@ class TypeDeChamp < ApplicationRecord
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
# see self.parse_drop_down_list_value
# then rails decided to add this blank ("") option when the select is required

View file

@ -74,7 +74,7 @@ describe RoutingEngine, type: :model do
context 'with a matching rule' 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')
end