def attach_beneficiary_import_details( beneficiary: users_models.User, application_id: int, source_id: int, source: BeneficiaryImportSources, details: str, status: ImportStatus = ImportStatus.CREATED, ) -> None: beneficiary_import = BeneficiaryImport.query.filter_by( applicationId=application_id, sourceId=source_id, source=source.value, beneficiary=beneficiary, ).one_or_none() if not beneficiary_import: beneficiary_import = BeneficiaryImport( applicationId=application_id, sourceId=source_id, source=source.value, beneficiary=beneficiary, ) beneficiary_import.setStatus(status=status, detail=details) beneficiary_import.beneficiary = beneficiary pcapi_repository.repository.save(beneficiary_import)
def attach_beneficiary_import_details( beneficiary: User, beneficiary_pre_subscription: BeneficiaryPreSubscription, status: ImportStatus = ImportStatus.CREATED, ) -> None: beneficiary_import = BeneficiaryImport.query.filter_by( applicationId=beneficiary_pre_subscription.application_id, sourceId=beneficiary_pre_subscription.source_id, source=beneficiary_pre_subscription.source, beneficiary=beneficiary, ).one_or_none() if not beneficiary_import: beneficiary_import = BeneficiaryImport() beneficiary_import.applicationId = beneficiary_pre_subscription.application_id beneficiary_import.sourceId = beneficiary_pre_subscription.source_id beneficiary_import.source = beneficiary_pre_subscription.source beneficiary_import.beneficiary = beneficiary beneficiary_import.setStatus(status=status) beneficiary_import.beneficiary = beneficiary repository.save(beneficiary_import)
def create_beneficiary_import( application_id: int = 99, date: datetime = datetime.utcnow(), detail: str = None, idx: int = None, source_id: int = settings.DMS_OLD_ENROLLMENT_PROCEDURE_ID, source: str = BeneficiaryImportSources.demarches_simplifiees.value, status: ImportStatus = ImportStatus.CREATED, user: User = None, ) -> BeneficiaryImport: import_status = BeneficiaryImportStatus() import_status.date = date import_status.detail = detail import_status.status = status beneficiary_import = BeneficiaryImport() beneficiary_import.id = idx beneficiary_import.beneficiary = user beneficiary_import.applicationId = application_id beneficiary_import.sourceId = source_id beneficiary_import.source = source beneficiary_import.statuses = [import_status] return beneficiary_import