Merge pull request #10053 from tchak/fix-effectif-graphql
fix(entreprise): graphql effectif
This commit is contained in:
commit
a03d6de190
6 changed files with 43 additions and 13 deletions
|
@ -45,7 +45,7 @@ module Types
|
|||
end
|
||||
|
||||
def effectif_mensuel
|
||||
if object.effectif_mensuel.present?
|
||||
if object.effectif_mensuel?
|
||||
{
|
||||
periode: [object.effectif_mois, object.effectif_annee].join('/'),
|
||||
nb: object.effectif_mensuel
|
||||
|
@ -53,6 +53,15 @@ module Types
|
|||
end
|
||||
end
|
||||
|
||||
def effectif_annuel
|
||||
if object.effectif_annuel?
|
||||
{
|
||||
periode: object.effectif_annuel_annee,
|
||||
nb: object.effectif_annuel
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def capital_social
|
||||
# capital_social is defined as a BigInt, so we can't return an empty string when value is unknown
|
||||
# 0 could appear to be a legitimate value, so a negative value helps to ensure the value is not known
|
||||
|
@ -72,15 +81,6 @@ module Types
|
|||
object.code_effectif_entreprise
|
||||
end
|
||||
|
||||
def effectif_annuel
|
||||
if object.effectif_annuel.present?
|
||||
{
|
||||
periode: object.effectif_annuel_annee,
|
||||
nb: object.effectif_annuel
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_attachment_for(key)
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
class APIEntreprise::EffectifsAnnuelsJob < APIEntreprise::Job
|
||||
def perform(etablissement_id, procedure_id)
|
||||
def perform(etablissement_id, procedure_id, year = default_year)
|
||||
find_etablissement(etablissement_id)
|
||||
etablissement_params = APIEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id).to_params
|
||||
etablissement_params = APIEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id, year).to_params
|
||||
etablissement.update!(etablissement_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_year
|
||||
Date.current.year - 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ class APIEntreprise::EffectifsAnnuelsAdapter < APIEntreprise::Adapter
|
|||
if effectifs.present?
|
||||
{
|
||||
entreprise_effectif_annuel: effectifs[:value],
|
||||
entreprise_effectif_annuel_annee: effectifs[:annee]
|
||||
entreprise_effectif_annuel_annee: data[:annee]
|
||||
}
|
||||
else
|
||||
{}
|
||||
|
|
|
@ -25,4 +25,12 @@ class Entreprise < Hashie::Dash
|
|||
property :enseigne, default: nil
|
||||
|
||||
property :inline_adresse
|
||||
|
||||
def effectif_mensuel?
|
||||
effectif_mensuel.present? && effectif_mois.present? && effectif_annee.present?
|
||||
end
|
||||
|
||||
def effectif_annuel?
|
||||
effectif_annuel.present? && effectif_annuel_annee.present?
|
||||
end
|
||||
end
|
||||
|
|
15
app/tasks/maintenance/backfill_effectif_annuel_annee_task.rb
Normal file
15
app/tasks/maintenance/backfill_effectif_annuel_annee_task.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Maintenance
|
||||
class BackfillEffectifAnnuelAnneeTask < MaintenanceTasks::Task
|
||||
def collection
|
||||
Etablissement.where.not(effectif_annuel: nil).where(effectif_annuel_annee: nil)
|
||||
end
|
||||
|
||||
def process(etablissement)
|
||||
year = etablissement.created_at.year - 1
|
||||
procedure = (etablissement.dossier || etablissement.champ&.dossier)&.procedure
|
||||
APIEntreprise::EffectifsAnnuelsJob.perform_later(etablissement.id, procedure&.id, year)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,5 +22,6 @@ RSpec.describe APIEntreprise::EffectifsAnnuelsJob, type: :job do
|
|||
it 'updates etablissement' do
|
||||
subject
|
||||
expect(Etablissement.find(etablissement.id).entreprise_effectif_annuel).to eq(100.5)
|
||||
expect(Etablissement.find(etablissement.id).entreprise_effectif_annuel_annee).to eq("2017")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue