From 12796051f5c75d36f4dde6ec10ef44d742e30cb5 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 23 Apr 2018 13:53:47 +0100 Subject: [PATCH 1/2] We need to rebuild the monthly billing for one service for the month of March. This change makes that possible without affecting any other data in the table. --- app/commands.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/commands.py b/app/commands.py index c1bc95710..0608215d9 100644 --- a/app/commands.py +++ b/app/commands.py @@ -185,9 +185,12 @@ def fix_notification_statuses_not_in_sync(): @notify_command() @click.option('-y', '--year', required=True, help="e.g. 2017", type=int) -def populate_monthly_billing(year): +@click.option('-s', '--service_id', required=False, help="Enter the service id", type=click.UUID) +@click.option('-m', '--month', required=False, help="e.g. 1 for January", type=int) +def populate_monthly_billing(year, service_id=None, month=None): """ Populate monthly billing table for all services for a given year. + If service_id and month provided then only rebuild monthly billing for that month. """ def populate(service_id, year, month): create_or_update_monthly_billing(service_id, datetime(year, month, 1)) @@ -201,11 +204,14 @@ def populate_monthly_billing(year): service_id, datetime(year, month, 1), 'letter' ) - print("Finished populating data for {} for service id {}".format(month, str(service_id))) + print("Finished populating data for {}-{} for service id {}".format(month, year, str(service_id))) print('SMS: {}'.format(sms_res.monthly_totals)) print('Email: {}'.format(email_res.monthly_totals)) print('Letter: {}'.format(letter_res.monthly_totals)) + if service_id and month: + populate(service_id, year, month) + service_ids = get_service_ids_that_need_billing_populated( start_date=datetime(2016, 5, 1), end_date=datetime(2017, 8, 16) ) From a91b46dfa9b3620388e4b03078795a8c72809d5e Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 23 Apr 2018 16:16:41 +0100 Subject: [PATCH 2/2] Added the else so the entire table does not rebuild. --- app/commands.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/commands.py b/app/commands.py index 0608215d9..ed72a78f4 100644 --- a/app/commands.py +++ b/app/commands.py @@ -211,21 +211,21 @@ def populate_monthly_billing(year, service_id=None, month=None): if service_id and month: populate(service_id, year, month) + else: + service_ids = get_service_ids_that_need_billing_populated( + start_date=datetime(2016, 5, 1), end_date=datetime(2017, 8, 16) + ) + start, end = 1, 13 - service_ids = get_service_ids_that_need_billing_populated( - start_date=datetime(2016, 5, 1), end_date=datetime(2017, 8, 16) - ) - start, end = 1, 13 + if year == 2016: + start = 4 - 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) + 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()