Merge pull request #10749 from mfo/US/commune-without-insee

correctif: ETQ administrateur/instructeur, je souhaite que les champs de type commune aient tjr un code insee afin de router de maniere fiable
This commit is contained in:
mfo 2024-09-06 11:44:00 +00:00 committed by GitHub
commit 915779c9b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 305 additions and 68 deletions

View file

@ -4,6 +4,9 @@ class Champs::CommuneChamp < Champs::TextChamp
store_accessor :value_json, :code_departement, :code_postal, :code_region
before_save :on_codes_change, if: :should_refresh_after_code_change?
validates :external_id, presence: true, if: -> { validate_champ_value_or_prefill? && value.present? }
after_validation :instrument_external_id_error, if: -> { errors.include?(:external_id) }
def departement_name
APIGeoService.departement_name(code_departement)
end
@ -101,4 +104,11 @@ class Champs::CommuneChamp < Champs::TextChamp
def should_refresh_after_code_change?
!departement? || code_postal_changed? || external_id_changed?
end
def instrument_external_id_error
Sentry.capture_message(
"Commune with value and no external id Edge case reached",
extra: { request_id: Current.request_id }
)
end
end