Merge pull request #7580 from betagouv/feat-instructeur-entreprise-etat
feat(etablissement) list entreprise "état administratif"
This commit is contained in:
commit
7c0fd0651d
17 changed files with 106 additions and 3 deletions
|
@ -1461,6 +1461,7 @@ type Entreprise {
|
|||
effectif pour un mois donné
|
||||
"""
|
||||
effectifMensuel: Effectif
|
||||
etatAdministratif: EntrepriseEtatAdministratif
|
||||
formeJuridique: String
|
||||
formeJuridiqueCode: String
|
||||
inlineAdresse: String!
|
||||
|
@ -1473,6 +1474,18 @@ type Entreprise {
|
|||
siretSiegeSocial: String!
|
||||
}
|
||||
|
||||
enum EntrepriseEtatAdministratif {
|
||||
"""
|
||||
L'entreprise est en activité
|
||||
"""
|
||||
Actif
|
||||
|
||||
"""
|
||||
L'entreprise a cessé son activité
|
||||
"""
|
||||
Ferme
|
||||
}
|
||||
|
||||
type File {
|
||||
byteSize: Int! @deprecated(reason: "Utilisez le champ `byteSizeBigInt` à la place.")
|
||||
byteSizeBigInt: BigInt!
|
||||
|
|
|
@ -6,6 +6,11 @@ module Types
|
|||
field :nb, Float, null: false
|
||||
end
|
||||
|
||||
class EntrepriseEtatAdministratifType < Types::BaseEnum
|
||||
value("Actif", "L'entreprise est en activité", value: Etablissement.entreprise_etat_administratifs.fetch("actif"))
|
||||
value("Ferme", "L'entreprise a cessé son activité", value: Etablissement.entreprise_etat_administratifs.fetch("fermé"))
|
||||
end
|
||||
|
||||
field :siren, String, null: false
|
||||
field :capital_social, GraphQL::Types::BigInt, null: true, description: "capital social de l’entreprise. -1 si inconnu."
|
||||
field :numero_tva_intracommunautaire, String, null: true
|
||||
|
@ -18,6 +23,7 @@ module Types
|
|||
field :effectif_mensuel, EffectifType, null: true, description: "effectif pour un mois donné"
|
||||
field :effectif_annuel, EffectifType, null: true, description: "effectif moyen d’une année"
|
||||
field :date_creation, GraphQL::Types::ISO8601Date, null: false
|
||||
field :etat_administratif, EntrepriseEtatAdministratifType, null: true
|
||||
field :nom, String, null: true
|
||||
field :prenom, String, null: true
|
||||
field :inline_adresse, String, null: false
|
||||
|
|
|
@ -39,4 +39,13 @@ module EtablissementHelper
|
|||
def pretty_date_exercice(date)
|
||||
date.sub(/(?<year>\d{4})(?<month>\d{2})/, '\k<year>') if date.present?
|
||||
end
|
||||
|
||||
def humanized_entreprise_etat_administratif(etablissement)
|
||||
case etablissement.entreprise_etat_administratif&.to_sym
|
||||
when :actif
|
||||
"en activité"
|
||||
when :fermé
|
||||
"fermé"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
|||
|
||||
def process_params
|
||||
params = data_source[:entreprise]&.slice(*attr_to_fetch)
|
||||
params[:etat_administratif] = map_etat_administratif(data_source)
|
||||
|
||||
if params.present? && valid_params?(params)
|
||||
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime
|
||||
|
@ -32,4 +33,13 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
|||
:prenom
|
||||
]
|
||||
end
|
||||
|
||||
def map_etat_administratif(data_source)
|
||||
raw_value = data_source.dig(:entreprise, :etat_administratif, :value) # data structure will change in v3
|
||||
|
||||
case raw_value
|
||||
when 'A' then 'actif'
|
||||
when 'F' then 'fermé'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1050,6 +1050,7 @@ class Dossier < ApplicationRecord
|
|||
['Entreprise SIRET siège social', etablissement&.entreprise_siret_siege_social],
|
||||
['Entreprise code effectif entreprise', etablissement&.entreprise_code_effectif_entreprise],
|
||||
['Entreprise date de création', etablissement&.entreprise_date_creation],
|
||||
['Entreprise état administratif', etablissement&.entreprise_etat_administratif],
|
||||
['Entreprise nom', etablissement&.entreprise_nom],
|
||||
['Entreprise prénom', etablissement&.entreprise_prenom],
|
||||
['Association RNA', etablissement&.association_rna],
|
||||
|
|
|
@ -13,6 +13,7 @@ class Entreprise < Hashie::Dash
|
|||
property :raison_sociale
|
||||
property :siret_siege_social
|
||||
property :code_effectif_entreprise
|
||||
property :etat_administratif
|
||||
property :effectif_mois
|
||||
property :effectif_annee
|
||||
property :effectif_mensuel
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
# entreprise_effectif_annuel_annee :string
|
||||
# entreprise_effectif_mensuel :decimal(, )
|
||||
# entreprise_effectif_mois :string
|
||||
# entreprise_etat_administratif :string
|
||||
# entreprise_forme_juridique :string
|
||||
# entreprise_forme_juridique_code :string
|
||||
# entreprise_nom :string
|
||||
|
@ -60,6 +61,11 @@ class Etablissement < ApplicationRecord
|
|||
validates :siret, presence: true
|
||||
validates :dossier_id, uniqueness: { allow_nil: true }
|
||||
|
||||
enum entreprise_etat_administratif: {
|
||||
actif: "actif",
|
||||
fermé: "fermé"
|
||||
}, _prefix: true
|
||||
|
||||
def search_terms
|
||||
[
|
||||
entreprise_siren,
|
||||
|
@ -112,6 +118,7 @@ class Etablissement < ApplicationRecord
|
|||
['Entreprise SIRET siège social', :entreprise_siret_siege_social],
|
||||
['Entreprise code effectif entreprise', :entreprise_code_effectif_entreprise],
|
||||
['Entreprise date de création', :entreprise_date_creation],
|
||||
['Entreprise état administratif', :entreprise_etat_administratif],
|
||||
['Entreprise nom', :entreprise_nom],
|
||||
['Entreprise prénom', :entreprise_prenom],
|
||||
['Association RNA', :association_rna],
|
||||
|
@ -162,6 +169,7 @@ class Etablissement < ApplicationRecord
|
|||
effectif_annuel: entreprise_effectif_annuel,
|
||||
effectif_annuel_annee: entreprise_effectif_annuel_annee,
|
||||
date_creation: entreprise_date_creation,
|
||||
etat_administratif: entreprise_etat_administratif,
|
||||
nom: entreprise_nom,
|
||||
prenom: entreprise_prenom,
|
||||
inline_adresse: inline_adresse
|
||||
|
|
|
@ -102,6 +102,10 @@ def add_identite_etablissement(pdf, etablissement)
|
|||
format_in_2_columns(pdf, "Code NAF ", etablissement.naf)
|
||||
format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.entreprise.date_creation))
|
||||
|
||||
if etablissement.entreprise_etat_administratif.present?
|
||||
format_in_2_columns(pdf, "État administratif", humanized_entreprise_etat_administratif(etablissement))
|
||||
end
|
||||
|
||||
if @include_infos_administration
|
||||
if etablissement.entreprise_effectif_mensuel.present?
|
||||
format_in_2_columns(pdf, "Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) ", number_with_delimiter(etablissement.entreprise_effectif_mensuel.to_s))
|
||||
|
|
|
@ -27,7 +27,12 @@
|
|||
%td= etablissement.naf
|
||||
%tr
|
||||
%td.libelle Date de création :
|
||||
%td= try_format_date(etablissement.entreprise.date_creation)
|
||||
%td
|
||||
= try_format_date(etablissement.entreprise.date_creation)
|
||||
|
||||
- if etablissement.entreprise_etat_administratif.present?
|
||||
%span.label= humanized_entreprise_etat_administratif(etablissement)
|
||||
|
||||
- if profile == 'instructeur'
|
||||
%tr
|
||||
%td.libelle
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddEntrepriseEtatAdministratifToEtablissements < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :etablissements, :entreprise_etat_administratif, :string
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_07_08_152039) do
|
||||
ActiveRecord::Schema.define(version: 2022_07_18_093034) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
|
@ -376,6 +376,7 @@ ActiveRecord::Schema.define(version: 2022_07_08_152039) do
|
|||
t.string "entreprise_effectif_annuel_annee"
|
||||
t.decimal "entreprise_effectif_mensuel"
|
||||
t.string "entreprise_effectif_mois"
|
||||
t.string "entreprise_etat_administratif"
|
||||
t.string "entreprise_forme_juridique"
|
||||
t.string "entreprise_forme_juridique_code"
|
||||
t.string "entreprise_nom"
|
||||
|
|
|
@ -23,6 +23,7 @@ FactoryBot.define do
|
|||
entreprise_siret_siege_social { '44011762001530' }
|
||||
entreprise_code_effectif_entreprise { '51' }
|
||||
entreprise_date_creation { "1990-04-24" }
|
||||
entreprise_etat_administratif { :actif }
|
||||
|
||||
trait :with_exercices do
|
||||
exercices { [association(:exercice)] }
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
"date_reference": "2014",
|
||||
"intitule": "200 à 249 salariés"
|
||||
},
|
||||
"etat_administratif": {
|
||||
"value": "A",
|
||||
"date_cessation": null
|
||||
},
|
||||
"exercices": [
|
||||
{
|
||||
"chiffre_affaires": null,
|
||||
|
|
|
@ -4,12 +4,14 @@ RSpec.describe EtablissementHelper, type: :helper do
|
|||
let(:enseigne) { "mon enseigne" }
|
||||
let(:nom) { 'mon nom' }
|
||||
let(:prenom) { 'mon prenom' }
|
||||
let(:etat_administratif) { 'actif' }
|
||||
let(:etablissement_params) do
|
||||
{
|
||||
enseigne: enseigne,
|
||||
entreprise_capital_social: 123_000,
|
||||
entreprise_code_effectif_entreprise: code_effectif,
|
||||
entreprise_raison_sociale: raison_sociale,
|
||||
entreprise_etat_administratif: etat_administratif,
|
||||
entreprise_nom: nom,
|
||||
entreprise_prenom: prenom
|
||||
}
|
||||
|
@ -72,4 +74,23 @@ RSpec.describe EtablissementHelper, type: :helper do
|
|||
subject { pretty_date_exercice("201908") }
|
||||
it { is_expected.to eq("2019") }
|
||||
end
|
||||
|
||||
describe "#humanized_entreprise_etat_administratif" do
|
||||
subject { humanized_entreprise_etat_administratif(etablissement) }
|
||||
|
||||
context "when etat_administratif is A" do
|
||||
let(:etat_administratif) { "actif" }
|
||||
it { is_expected.to eq("en activité") }
|
||||
end
|
||||
|
||||
context "when etat_administratif is F" do
|
||||
let(:etat_administratif) { "fermé" }
|
||||
it { is_expected.to eq("fermé") }
|
||||
end
|
||||
|
||||
context "when etat_administratif is nil" do
|
||||
let(:etat_administratif) { nil }
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siren) { '418166096' }
|
||||
let(:etablissement) { create(:etablissement, siret: siret) }
|
||||
let(:etablissement) { create(:etablissement, siret: siret, entreprise_etat_administratif: nil) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
|
||||
|
@ -19,4 +19,12 @@ RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
|
|||
subject
|
||||
expect(Etablissement.find(etablissement.id).entreprise_numero_tva_intracommunautaire).to eq('FR16418166096')
|
||||
end
|
||||
|
||||
it 'convert entreprise etat_administratif source to an enum' do
|
||||
subject
|
||||
etablissement.reload
|
||||
|
||||
expect(etablissement.entreprise_etat_administratif).to eq("actif")
|
||||
expect(etablissement.entreprise_etat_administratif_actif?)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,6 +67,10 @@ describe APIEntreprise::EntrepriseAdapter do
|
|||
it 'L\'entreprise contient bien un prenom' do
|
||||
expect(subject[:entreprise_prenom]).to eq('test_prenom')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un etat administratif' do
|
||||
expect(subject[:entreprise_etat_administratif]).to eq('actif')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -211,6 +211,7 @@ describe ProcedureExportService do
|
|||
"Entreprise SIRET siège social",
|
||||
"Entreprise code effectif entreprise",
|
||||
"Entreprise date de création",
|
||||
"Entreprise état administratif",
|
||||
"Entreprise nom",
|
||||
"Entreprise prénom",
|
||||
"Association RNA",
|
||||
|
@ -300,6 +301,7 @@ describe ProcedureExportService do
|
|||
"Entreprise SIRET siège social",
|
||||
"Entreprise code effectif entreprise",
|
||||
"Entreprise date de création",
|
||||
"Entreprise état administratif",
|
||||
"Entreprise nom",
|
||||
"Entreprise prénom",
|
||||
"Association RNA",
|
||||
|
|
Loading…
Add table
Reference in a new issue