mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-27 09:28:03 -04:00
Add letter type when getting billing data for financial year
This commit is contained in:
@@ -214,7 +214,6 @@ def populate_monthly_billing(year):
|
||||
print('Email: {}'.format(email_res.monthly_totals))
|
||||
print('Letter: {}'.format(letter_res.monthly_totals))
|
||||
|
||||
|
||||
service_ids = get_service_ids_that_need_billing_populated(
|
||||
start_date=datetime(2016, 5, 1), end_date=datetime(2017, 8, 16)
|
||||
)
|
||||
@@ -223,13 +222,12 @@ def populate_monthly_billing(year):
|
||||
if year == 2016:
|
||||
start = 4
|
||||
|
||||
# for service_id in service_ids:
|
||||
# print('Starting to populate data for service {}'.format(str(service_id)))
|
||||
# print('Starting populating monthly billing for {}'.format(year))
|
||||
# for i in range(start, end):
|
||||
# print('Population for {}-{}'.format(i, year))
|
||||
# populate(service_id, year, i)
|
||||
populate('56fa9fd8-61de-4688-8bc7-2908a77367df', year, 10)
|
||||
for service_id in service_ids:
|
||||
print('Starting to populate data for service {}'.format(str(service_id)))
|
||||
print('Starting populating monthly billing for {}'.format(year))
|
||||
for i in range(start, end):
|
||||
print('Population for {}-{}'.format(i, year))
|
||||
populate(service_id, year, i)
|
||||
|
||||
|
||||
@notify_command()
|
||||
|
||||
@@ -8,9 +8,9 @@ from app.dao.notification_usage_dao import get_billing_data_for_month
|
||||
from app.models import (
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE,
|
||||
LETTER_TYPE,
|
||||
MonthlyBilling,
|
||||
NotificationHistory,
|
||||
LETTER_TYPE
|
||||
NotificationHistory
|
||||
)
|
||||
from app.statsd_decorators import statsd
|
||||
from app.utils import convert_utc_to_bst
|
||||
@@ -22,7 +22,7 @@ def get_service_ids_that_need_billing_populated(start_date, end_date):
|
||||
).filter(
|
||||
NotificationHistory.created_at >= start_date,
|
||||
NotificationHistory.created_at <= end_date,
|
||||
NotificationHistory.notification_type.in_([SMS_TYPE, EMAIL_TYPE]),
|
||||
NotificationHistory.notification_type.in_([SMS_TYPE, EMAIL_TYPE, LETTER_TYPE]),
|
||||
NotificationHistory.billable_units != 0
|
||||
).distinct().all()
|
||||
|
||||
@@ -30,8 +30,8 @@ def get_service_ids_that_need_billing_populated(start_date, end_date):
|
||||
@statsd(namespace="dao")
|
||||
def create_or_update_monthly_billing(service_id, billing_month):
|
||||
start_date, end_date = get_month_start_and_end_date_in_utc(billing_month)
|
||||
# _update_monthly_billing(service_id, start_date, end_date, SMS_TYPE)
|
||||
# _update_monthly_billing(service_id, start_date, end_date, EMAIL_TYPE)
|
||||
_update_monthly_billing(service_id, start_date, end_date, SMS_TYPE)
|
||||
_update_monthly_billing(service_id, start_date, end_date, EMAIL_TYPE)
|
||||
_update_monthly_billing(service_id, start_date, end_date, LETTER_TYPE)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from app.dao.monthly_billing_dao import (
|
||||
create_or_update_monthly_billing,
|
||||
get_monthly_billing_by_notification_type,
|
||||
)
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, LETTER_TYPE
|
||||
from app.dao.date_util import get_current_financial_year_start_year
|
||||
from app.dao.annual_billing_dao import dao_get_free_sms_fragment_limit_for_year
|
||||
from tests.app.db import (
|
||||
@@ -54,7 +54,7 @@ def test_get_yearly_billing_summary_returns_correct_breakdown(client, sample_tem
|
||||
assert response.status_code == 200
|
||||
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert len(resp_json) == 2
|
||||
assert len(resp_json) == 3
|
||||
|
||||
_assert_dict_equals(resp_json[0], {
|
||||
'notification_type': SMS_TYPE,
|
||||
@@ -67,6 +67,11 @@ def test_get_yearly_billing_summary_returns_correct_breakdown(client, sample_tem
|
||||
'billing_units': 0,
|
||||
'rate': 0
|
||||
})
|
||||
_assert_dict_equals(resp_json[2], {
|
||||
'notification_type': LETTER_TYPE,
|
||||
'billing_units': 0,
|
||||
'rate': 0
|
||||
})
|
||||
|
||||
|
||||
def test_get_yearly_billing_usage_breakdown_returns_400_if_missing_year(client, sample_service):
|
||||
@@ -125,20 +130,32 @@ def test_get_yearly_usage_by_month_returns_correctly(client, sample_template):
|
||||
assert response.status_code == 200
|
||||
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
|
||||
print(resp_json)
|
||||
_assert_dict_equals(resp_json[0], {
|
||||
'billing_units': 2,
|
||||
'month': 'May',
|
||||
'notification_type': SMS_TYPE,
|
||||
'rate': 0.12
|
||||
})
|
||||
|
||||
_assert_dict_equals(resp_json[1], {
|
||||
'billing_units': 0,
|
||||
'month': 'May',
|
||||
'notification_type': LETTER_TYPE,
|
||||
'rate': 0
|
||||
})
|
||||
|
||||
_assert_dict_equals(resp_json[2], {
|
||||
'billing_units': 6,
|
||||
'month': 'June',
|
||||
'notification_type': SMS_TYPE,
|
||||
'rate': 0.12
|
||||
})
|
||||
_assert_dict_equals(resp_json[3], {
|
||||
'billing_units': 0,
|
||||
'month': 'June',
|
||||
'notification_type': LETTER_TYPE,
|
||||
'rate': 0
|
||||
})
|
||||
|
||||
|
||||
def test_transform_billing_for_month_returns_empty_if_no_monthly_totals(sample_service):
|
||||
|
||||
Reference in New Issue
Block a user