def schedule_export(enterprise_id, user): google_sheet_object = GoogleSpreadSheet() export = Export.objects.filter(enterprise_id=enterprise_id).first() sheet_id = export.google_sheets_link if export else google_sheet_object.create_sheet( ) export, _ = Export.objects.update_or_create(enterprise_id=enterprise_id, defaults={ 'status': DEFAULT_SYNC_STATUS, 'google_sheets_link': sheet_id, }) fyle_credentials = AuthToken.objects.get(user__user_id=user) fyle_connector = FyleConnector(fyle_credentials.refresh_token) created_job = fyle_connector.trigger_job( callback_url='{0}{1}'.format( settings.API_URL, '/enterprises/{0}/exports/'.format(enterprise_id)), callback_method='POST', object_id=export.id, payload={}, job_description='Running export for Enterprise id: {0}'.format( enterprise_id), org_user_id=fyle_connector.get_employee_profile()['id']) export.job_id = created_job['id'] export.save() return created_job
def get(self, request, *args, **kwargs): """ Get User Details """ fyle_credentials = AuthToken.objects.get(user__user_id=request.user) fyle_connector = FyleConnector(fyle_credentials.refresh_token) employee_profile = fyle_connector.get_employee_profile() return Response(data=employee_profile, status=status.HTTP_200_OK)