Change the updates to only look at today, and not yesterday.

This commit is contained in:
Rebecca Law
2020-02-26 17:38:20 +00:00
parent f7a564a17c
commit c91f37ff4c
5 changed files with 19 additions and 13 deletions

View File

@@ -244,11 +244,9 @@ def fetch_monthly_billing_for_year(service_id, year):
today = convert_utc_to_bst(datetime.utcnow()).date()
# if year end date is less than today, we are calculating for data in the past and have no need for deltas.
if year_end_date >= today:
yesterday = today - timedelta(days=1)
for day in [yesterday, today]:
data = fetch_billing_data_for_day(process_day=day, service_id=service_id, check_permissions=True)
for d in data:
update_fact_billing(data=d, process_day=day)
data = fetch_billing_data_for_day(process_day=today, service_id=service_id, check_permissions=True)
for d in data:
update_fact_billing(data=d, process_day=today)
email_and_letters = db.session.query(
func.date_trunc('month', FactBilling.bst_date).cast(Date).label("month"),
@@ -648,12 +646,10 @@ def fetch_usage_year_for_organisation(organisation_id, year):
services = dao_get_organisation_live_services(organisation_id)
# if year end date is less than today, we are calculating for data in the past and have no need for deltas.
if year_end_date >= today:
yesterday = today - timedelta(days=1)
for service in services:
for day in [yesterday, today]:
data = fetch_billing_data_for_day(process_day=day, service_id=service.id)
for d in data:
update_fact_billing(data=d, process_day=day)
data = fetch_billing_data_for_day(process_day=today, service_id=service.id)
for d in data:
update_fact_billing(data=d, process_day=today)
service_with_usage = {}
# initialise results
for service in services:

View File

@@ -130,7 +130,7 @@ def get_organisation_services(organisation_id):
@organisation_blueprint.route('/<uuid:organisation_id>/services-with-usage', methods=['GET'])
def get_organisation_services_usage(organisation_id):
try:
year = int(request.args.get('year'))
year = int(request.args.get('year', 'none'))
except ValueError:
return jsonify(result='error', message='No valid year provided'), 400
services = fetch_usage_year_for_organisation(organisation_id, year)

View File

@@ -631,6 +631,7 @@ def test_fetch_letter_line_items_for_all_service(notify_db_session):
assert results[4] == (None, None, service_3.name, service_3.id, Decimal("0.55"), 'second', 15)
@freeze_time('2019-06-01 13:30')
def test_fetch_usage_year_for_organisation(notify_db_session):
org, org_2, service, service_2, service_3, service_sms_only, \
org_with_emails, service_with_emails = set_up_usage_data(datetime(2019, 5, 1))

View File

@@ -908,7 +908,7 @@ def set_up_usage_data(start_date):
service_2 = create_service(service_name='b - emails')
email_template = create_template(service=service_2, template_type='email')
org_2 = create_organisation(name='Org for {}'.format(service_2))
org_2 = create_organisation(name='Org for {}'.format(service_2.name))
dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id)
service_3 = create_service(service_name='c - letters only')

View File

@@ -777,7 +777,16 @@ def test_get_organisation_services_usage_returns_400_if_year_is_invalid(admin_re
response = admin_request.get(
'organisation.get_organisation_services_usage',
organisation_id=uuid.uuid4(),
**{"year": 'year'},
**{"year": 'not-a-valid-year'},
_expected_status=400
)
assert response['message'] == 'No valid year provided'
def test_get_organisation_services_usage_returns_400_if_year_is_empty(admin_request):
response = admin_request.get(
'organisation.get_organisation_services_usage',
organisation_id=uuid.uuid4(),
_expected_status=400
)
assert response['message'] == 'No valid year provided'