def add_organisation_from_nhs_local_service(service_id): if (not current_service.organisation_type == Organisation.TYPE_NHS_LOCAL) or current_service.organisation: abort(403) form = AddNHSLocalOrganisationForm( organisation_choices=[(organisation.id, organisation.name) for organisation in Organisations() if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL]) search_form = SearchByNameForm() if form.validate_on_submit(): Organisation.from_id( form.organisations.data).associate_service(service_id) return redirect(url_for( '.service_agreement', service_id=service_id, )) return render_template( 'views/organisations/add-nhs-local-organisation.html', form=form, search_form=search_form, )
def usage_for_all_services_by_organisation(): form = GetServicesByOrganisationForm() list_organisation = [("", "Tous")] for org in Organisations(): list_organisation.append(tuple((org.id, org.name))) form.organisations.choices = list_organisation if form.validate_on_submit(): organisation_id = form.organisations.data start_date = form.start_date.data end_date = form.end_date.data headers = [translate("Start Date"), translate("End Date"), translate("Organisation ID"), translate("Organisation name"), translate("Sagir Code"), translate("Service ID"), translate("Service name"), translate("Restricted"), translate("Details Type"), translate("Provider Name"), translate("Number Sent"), translate("Billable Units")] result = billing_api_client.get_usage_for_all_services_by_organisation(organisation_id, start_date, end_date) rows = [] if result: for key, value in result["PGNUtilization"]["Organisations"].items(): for servKey, servValue in value["services"].items(): details = {} if servValue["email_details"] != {}: details["email"] = servValue["email_details"] if servValue["sms_details"] != {}: details["sms"] = servValue["sms_details"] for detailsKey, detailsValue in details.items(): for subDetailsKey, subDetailsValue in detailsValue["providers"].items(): if detailsKey == "sms": details_type = "SMS" details_billable = subDetailsValue["billable_units"] else: details_type = "Email" details_billable = "" rows.append([str(start_date), str(end_date), value["organisation_id"], key, value["sagir_code"], servValue["service_id"], servKey, translate("Trial") if servValue["restricted"] else translate("Live") , details_type, subDetailsKey, subDetailsValue["number_sent"], details_billable]) return Spreadsheet.from_rows([headers] + rows).as_excel_file, 200, { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Content-Disposition': 'attachment; filename="Usage for all services by organisation from {} to {}.xlsx"'.format( start_date, end_date ) } else: flash('No results for dates') return render_template( 'views/platform-admin/usage_for_all_services_by_organisation.html', form=form )
def choose_account(): org_count, live_service_count = None, None if current_user.platform_admin: org_count, live_service_count = ( len(Organisations()), status_api_client.get_count_of_live_services_and_organisations() ["services"], ) return render_template( "views/choose-account.html", can_add_service=current_user.is_gov_user, org_count=org_count, live_service_count=live_service_count, )
def organisations(): return render_template( 'views/organisations/index.html', organisations=Organisations(), search_form=SearchByNameForm(), )