2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-29 10:47:43 +02:00
|
|
|
module RoutingEngine
|
2024-04-09 16:22:43 +02:00
|
|
|
def self.compute(dossier, assignment_mode: DossierAssignment.modes.fetch(:auto))
|
2023-05-25 16:02:47 +02:00
|
|
|
return if dossier.forced_groupe_instructeur
|
2023-04-14 10:38:45 +02:00
|
|
|
|
2023-06-16 15:11:33 +02:00
|
|
|
matching_groupe = dossier.procedure.groupe_instructeurs.active.reject(&:invalid_rule?).find do |gi|
|
2024-11-06 22:30:31 +01:00
|
|
|
gi.routing_rule&.compute(dossier.filled_champs)
|
2023-03-29 10:47:43 +02:00
|
|
|
end
|
2023-06-30 14:21:58 +02:00
|
|
|
|
2023-03-29 10:47:43 +02:00
|
|
|
matching_groupe ||= dossier.procedure.defaut_groupe_instructeur
|
2023-06-30 14:21:58 +02:00
|
|
|
|
2024-04-09 16:22:43 +02:00
|
|
|
dossier.assign_to_groupe_instructeur(matching_groupe, assignment_mode)
|
2023-03-29 10:47:43 +02:00
|
|
|
end
|
|
|
|
end
|