Add SIRET Type De Champ
This commit is contained in:
parent
0b79a3d79d
commit
45ef32e6d9
18 changed files with 210 additions and 5 deletions
|
@ -8,7 +8,10 @@ class Etablissement < ApplicationRecord
|
|||
accepts_nested_attributes_for :exercices
|
||||
accepts_nested_attributes_for :entreprise, update_only: true
|
||||
|
||||
validates :dossier_id, uniqueness: true
|
||||
validates :siret, presence: true
|
||||
validates :dossier_id, uniqueness: { allow_nil: true }
|
||||
|
||||
validate :validate_signature
|
||||
|
||||
def geo_adresse
|
||||
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
|
||||
|
@ -18,6 +21,11 @@ class Etablissement < ApplicationRecord
|
|||
# squeeze needed because of space in excess in the data
|
||||
"#{numero_voie} #{type_voie} #{nom_voie}, #{complement_adresse}, #{code_postal} #{localite}".squeeze(' ')
|
||||
end
|
||||
|
||||
def titre
|
||||
entreprise_raison_sociale || association_titre
|
||||
end
|
||||
|
||||
def verify
|
||||
SignatureService.verify(signature, message_for_signature)
|
||||
end
|
||||
|
@ -28,6 +36,14 @@ class Etablissement < ApplicationRecord
|
|||
|
||||
attr_accessor :signature
|
||||
|
||||
private
|
||||
|
||||
def validate_signature
|
||||
if champ && !verify
|
||||
errors.add(:base, 'Numéro SIRET introuvable.')
|
||||
end
|
||||
end
|
||||
|
||||
def message_for_signature
|
||||
JSON.pretty_generate(as_json(include: {
|
||||
exercices: { only: [:ca, :date_fin_exercice, :date_fin_exercice_timestamp] }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue