2021-11-24 17:30:35 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: champs
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# data :jsonb
|
|
|
|
# fetch_external_data_exceptions :string is an Array
|
2022-12-01 12:00:21 +01:00
|
|
|
# prefilled :boolean default(FALSE)
|
2021-11-24 17:30:35 +01:00
|
|
|
# private :boolean default(FALSE), not null
|
|
|
|
# rebased_at :datetime
|
|
|
|
# row :integer
|
|
|
|
# type :string
|
|
|
|
# value :string
|
|
|
|
# value_json :jsonb
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2022-09-21 15:20:42 +02:00
|
|
|
# dossier_id :integer
|
2021-11-24 17:30:35 +01:00
|
|
|
# etablissement_id :integer
|
|
|
|
# external_id :string
|
|
|
|
# parent_id :bigint
|
2022-12-16 12:39:51 +01:00
|
|
|
# row_id :string
|
2022-09-21 15:20:42 +02:00
|
|
|
# type_de_champ_id :integer
|
2021-11-24 17:30:35 +01:00
|
|
|
#
|
|
|
|
class Champs::DgfipChamp < Champs::TextChamp
|
|
|
|
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/dgfip-input-validation.middleware.ts
|
|
|
|
validates :numero_fiscal, format: { with: /\A\w{13,14}\z/ }, if: -> { reference_avis.present? && validation_context != :brouillon }
|
|
|
|
validates :reference_avis, format: { with: /\A\w{13,14}\z/ }, if: -> { numero_fiscal.present? && validation_context != :brouillon }
|
|
|
|
|
|
|
|
store_accessor :value_json, :numero_fiscal, :reference_avis
|
|
|
|
|
|
|
|
def blank?
|
|
|
|
external_id.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_external_data?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_external_data
|
|
|
|
if valid?
|
|
|
|
APIParticulier::DgfipAdapter.new(
|
|
|
|
procedure.api_particulier_token,
|
|
|
|
numero_fiscal,
|
|
|
|
reference_avis,
|
|
|
|
procedure.api_particulier_sources
|
|
|
|
).to_params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_id
|
|
|
|
if numero_fiscal.present? && reference_avis.present?
|
|
|
|
{ reference_avis: reference_avis, numero_fiscal: numero_fiscal }.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|