mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Update the ft_billing query to only include billable notification status types.
Update test_provider_statistics dao - this is really irrelevant since the endpoint using the query is not being used. We have a PR coming to delete the unused code. Update rate_multiplier to always be an integer
This commit is contained in:
@@ -446,6 +446,8 @@ def migrate_data_to_ft_billing(start_date, end_date):
|
|||||||
left join services s on s.id = n.service_id
|
left join services s on s.id = n.service_id
|
||||||
where n.notification_status!='technical-failure'
|
where n.notification_status!='technical-failure'
|
||||||
and n.key_type!='test'
|
and n.key_type!='test'
|
||||||
|
and n.notification_status in
|
||||||
|
('sending', 'sent', 'delivered', 'temporary-failure', 'permanent-failure', 'failed')
|
||||||
and n.notification_status!='created'
|
and n.notification_status!='created'
|
||||||
and n.created_at >= (date :start + time '00:00:00') at time zone 'Europe/London'
|
and n.created_at >= (date :start + time '00:00:00') at time zone 'Europe/London'
|
||||||
at time zone 'UTC'
|
at time zone 'UTC'
|
||||||
@@ -462,8 +464,8 @@ def migrate_data_to_ft_billing(start_date, end_date):
|
|||||||
|
|
||||||
result = db.session.execute(sql, {"start": process_date, "end": process_date + timedelta(days=1)})
|
result = db.session.execute(sql, {"start": process_date, "end": process_date + timedelta(days=1)})
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
current_app.logger.info('ft_billing: --- Completed took {}ms. Migrated {} rows.'.format(datetime.now() - start_time,
|
current_app.logger.info('ft_billing: --- Completed took {}ms. Migrated {} rows for {}'.format(
|
||||||
result.rowcount))
|
datetime.now() - start_time, result.rowcount, process_date))
|
||||||
|
|
||||||
process_date += timedelta(days=1)
|
process_date += timedelta(days=1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime, timedelta, time
|
from datetime import datetime, timedelta, time
|
||||||
|
|
||||||
from sqlalchemy.dialects.postgresql import insert
|
from sqlalchemy.dialects.postgresql import insert
|
||||||
from sqlalchemy import func, case, desc, Date
|
from sqlalchemy import func, case, desc, Date, Integer
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.date_util import get_financial_year
|
from app.dao.date_util import get_financial_year
|
||||||
@@ -9,14 +9,13 @@ from app.models import (
|
|||||||
FactBilling,
|
FactBilling,
|
||||||
Notification,
|
Notification,
|
||||||
Service,
|
Service,
|
||||||
NOTIFICATION_CREATED,
|
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
Rate,
|
Rate,
|
||||||
LetterRate,
|
LetterRate,
|
||||||
NotificationHistory
|
NotificationHistory,
|
||||||
|
NOTIFICATION_STATUS_TYPES_BILLABLE
|
||||||
)
|
)
|
||||||
from app.utils import convert_utc_to_bst, convert_bst_to_utc
|
from app.utils import convert_utc_to_bst, convert_bst_to_utc
|
||||||
|
|
||||||
@@ -104,14 +103,13 @@ def fetch_billing_data_for_day(process_day, service_id=None):
|
|||||||
(table.notification_type == 'email', 'ses')
|
(table.notification_type == 'email', 'ses')
|
||||||
]),
|
]),
|
||||||
).label('sent_by'),
|
).label('sent_by'),
|
||||||
func.coalesce(table.rate_multiplier, 1).label('rate_multiplier'),
|
func.coalesce(table.rate_multiplier, 1).cast(Integer).label('rate_multiplier'),
|
||||||
func.coalesce(table.international, False).label('international'),
|
func.coalesce(table.international, False).label('international'),
|
||||||
func.sum(table.billable_units).label('billable_units'),
|
func.sum(table.billable_units).label('billable_units'),
|
||||||
func.count().label('notifications_sent'),
|
func.count().label('notifications_sent'),
|
||||||
Service.crown,
|
Service.crown,
|
||||||
).filter(
|
).filter(
|
||||||
table.status != NOTIFICATION_CREATED, # at created status, provider information is not available
|
table.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE),
|
||||||
table.status != NOTIFICATION_TECHNICAL_FAILURE,
|
|
||||||
table.key_type != KEY_TYPE_TEST,
|
table.key_type != KEY_TYPE_TEST,
|
||||||
table.created_at >= start_date,
|
table.created_at >= start_date,
|
||||||
table.created_at < end_date
|
table.created_at < end_date
|
||||||
|
|||||||
@@ -1068,7 +1068,6 @@ NOTIFICATION_STATUS_TYPES_BILLABLE = [
|
|||||||
NOTIFICATION_SENT,
|
NOTIFICATION_SENT,
|
||||||
NOTIFICATION_DELIVERED,
|
NOTIFICATION_DELIVERED,
|
||||||
NOTIFICATION_FAILED,
|
NOTIFICATION_FAILED,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
|
||||||
NOTIFICATION_TEMPORARY_FAILURE,
|
NOTIFICATION_TEMPORARY_FAILURE,
|
||||||
NOTIFICATION_PERMANENT_FAILURE,
|
NOTIFICATION_PERMANENT_FAILURE,
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import uuid
|
|||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
||||||
from app.models import NotificationHistory, KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, NOTIFICATION_STATUS_TYPES
|
from app.models import (
|
||||||
|
NotificationHistory, KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST,
|
||||||
|
NOTIFICATION_STATUS_TYPES_BILLABLE
|
||||||
|
)
|
||||||
from app.dao.provider_statistics_dao import get_fragment_count
|
from app.dao.provider_statistics_dao import get_fragment_count
|
||||||
|
|
||||||
|
|
||||||
@@ -24,10 +27,10 @@ def test_get_fragment_count_separates_sms_and_email(notify_db, sample_template,
|
|||||||
|
|
||||||
|
|
||||||
def test_get_fragment_count_filters_on_status(notify_db, sample_template):
|
def test_get_fragment_count_filters_on_status(notify_db, sample_template):
|
||||||
for status in NOTIFICATION_STATUS_TYPES:
|
for status in NOTIFICATION_STATUS_TYPES_BILLABLE:
|
||||||
noti_hist(notify_db, sample_template, status=status)
|
noti_hist(notify_db, sample_template, status=status)
|
||||||
# sending, sent, delivered, failed, technical-failure, temporary-failure, permanent-failure
|
# sending, sent, delivered, failed, temporary-failure, permanent-failure
|
||||||
assert get_fragment_count(sample_template.service_id)['sms_count'] == 7
|
assert get_fragment_count(sample_template.service_id)['sms_count'] == 6
|
||||||
|
|
||||||
|
|
||||||
def test_get_fragment_count_filters_on_service_id(notify_db, sample_template, service_factory):
|
def test_get_fragment_count_filters_on_service_id(notify_db, sample_template, service_factory):
|
||||||
|
|||||||
Reference in New Issue
Block a user