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