mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-24 09:58:53 -04:00
update billing dao
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from flask import current_app
|
||||
from sqlalchemy import select, update
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit
|
||||
@@ -26,42 +27,51 @@ def dao_create_or_update_annual_billing_for_year(
|
||||
|
||||
|
||||
def dao_get_annual_billing(service_id):
|
||||
return (
|
||||
AnnualBilling.query.filter_by(
|
||||
stmt = (
|
||||
select(AnnualBilling)
|
||||
.filter_by(
|
||||
service_id=service_id,
|
||||
)
|
||||
.order_by(AnnualBilling.financial_year_start)
|
||||
.all()
|
||||
)
|
||||
return db.session.execute(stmt).scalars().all()
|
||||
|
||||
|
||||
@autocommit
|
||||
def dao_update_annual_billing_for_future_years(
|
||||
service_id, free_sms_fragment_limit, financial_year_start
|
||||
):
|
||||
AnnualBilling.query.filter(
|
||||
AnnualBilling.service_id == service_id,
|
||||
AnnualBilling.financial_year_start > financial_year_start,
|
||||
).update({"free_sms_fragment_limit": free_sms_fragment_limit})
|
||||
stmt = (
|
||||
update(AnnualBilling)
|
||||
.filter(
|
||||
AnnualBilling.service_id == service_id,
|
||||
AnnualBilling.financial_year_start > financial_year_start,
|
||||
)
|
||||
.values({"free_sms_fragment_limit": free_sms_fragment_limit})
|
||||
)
|
||||
db.session.execute(stmt)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start=None):
|
||||
if not financial_year_start:
|
||||
financial_year_start = get_current_calendar_year_start_year()
|
||||
|
||||
return AnnualBilling.query.filter_by(
|
||||
stmt = select(AnnualBilling).filter_by(
|
||||
service_id=service_id, financial_year_start=financial_year_start
|
||||
).first()
|
||||
)
|
||||
return db.session.execute(stmt).scalars().first()
|
||||
|
||||
|
||||
def dao_get_all_free_sms_fragment_limit(service_id):
|
||||
return (
|
||||
AnnualBilling.query.filter_by(
|
||||
stmt = (
|
||||
select(AnnualBilling)
|
||||
.filter_by(
|
||||
service_id=service_id,
|
||||
)
|
||||
.order_by(AnnualBilling.financial_year_start)
|
||||
.all()
|
||||
)
|
||||
return db.session.execute(stmt).scalars().all()
|
||||
|
||||
|
||||
def set_default_free_allowance_for_service(service, year_start=None):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import date, timedelta
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import Date, Integer, and_, desc, func, union
|
||||
from sqlalchemy import Date, Integer, and_, desc, func, select, union
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.sql.expression import case, literal
|
||||
|
||||
@@ -334,9 +334,8 @@ def query_service_sms_usage_for_year(service_id, year):
|
||||
free_allowance_used = func.least(
|
||||
remaining_free_allowance_before_this_row, this_rows_chargeable_units
|
||||
)
|
||||
|
||||
return (
|
||||
db.session.query(
|
||||
stmt = (
|
||||
select(
|
||||
FactBilling.local_date,
|
||||
FactBilling.notifications_sent,
|
||||
this_rows_chargeable_units.label("chargeable_units"),
|
||||
@@ -346,6 +345,7 @@ def query_service_sms_usage_for_year(service_id, year):
|
||||
free_allowance_used.label("free_allowance_used"),
|
||||
charged_units.label("charged_units"),
|
||||
)
|
||||
.select_from(FactBilling)
|
||||
.join(AnnualBilling, AnnualBilling.service_id == service_id)
|
||||
.filter(
|
||||
FactBilling.service_id == service_id,
|
||||
@@ -355,6 +355,7 @@ def query_service_sms_usage_for_year(service_id, year):
|
||||
AnnualBilling.financial_year_start == year,
|
||||
)
|
||||
)
|
||||
return stmt
|
||||
|
||||
|
||||
def delete_billing_data_for_service_for_day(process_day, service_id):
|
||||
|
||||
@@ -86,7 +86,7 @@ def _create_service_invite(invited_user, invite_link_host):
|
||||
redis_store.set(
|
||||
f"email-personalisation-{saved_notification.id}",
|
||||
json.dumps(personalisation),
|
||||
ex=2*24*60*60,
|
||||
ex=2 * 24 * 60 * 60,
|
||||
)
|
||||
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user