diff --git a/data/etl/teleicare_history/extractor.py b/data/etl/teleicare_history/extractor.py index 605646f7..42a7f203 100644 --- a/data/etl/teleicare_history/extractor.py +++ b/data/etl/teleicare_history/extractor.py @@ -1,6 +1,7 @@ import logging -from data.models import Company, IcaEtablissement +from data.models import Company, IcaEtablissement, IcaVersionDeclaration +from data.models.declaration import Declaration, DeclarationStatus logger = logging.getLogger(__name__) @@ -46,3 +47,26 @@ def match_companies_on_siret_or_vat(): logger.info( f"{nb_vat_match} + {nb_siret_match} entreprises réconcilliées sur {len(IcaEtablissement.objects.all())}" ) + + +def create_declaration_from_teleicare_history(): + for company in Company.objects.exclude(siccrf_id=None): + declared_food_supplements = IcaVersionDeclaration.object.filter( + etab_ident=company.siccrf_id, stattdcl_ident_in=[] + ) + len(declared_food_supplements) + declaration = Declaration() + declaration.save() + + +# Pout les déclarations TeleIcare, le status correspond au champ IcaVersionDeclaration.stattdcl_ident +DECLARATION_STATUS_MAPPING = { + 1: DeclarationStatus.ONGOING_INSTRUCTION, # 'en cours' + 2: DeclarationStatus.AUTHORIZED, # 'autorisé temporaire' + 3: DeclarationStatus.AUTHORIZED, # 'autorisé prolongé' + 4: DeclarationStatus.AUTHORIZED, # 'autorisé définitif' + 5: DeclarationStatus.REJECTED, # 'refusé' + 6: DeclarationStatus.WITHDRAWN, # 'arrêt commercialisation' + 7: DeclarationStatus.WITHDRAWN, # 'retiré du marché' + 8: DeclarationStatus.ABANDONED, # 'abandonné' +}