- Added a scheduled task to create or update billing for the month, yesterday is used to calculate the start and end date for the month.

- The new task has not been added to the beat application yet.
- Added an updated_at column to the monthly billing table, we may want to only calculate from the last updated date rather than the entire month.
This commit is contained in:
Rebecca Law
2017-07-24 15:13:18 +01:00
parent 793248a74f
commit 3e2b8190b9
7 changed files with 93 additions and 12 deletions

View File

@@ -1,12 +1,25 @@
from datetime import datetime
from app import db
from app.dao.date_util import get_month_start_end_date
from app.dao.notification_usage_dao import get_billing_data_for_month
from app.models import MonthlyBilling, SMS_TYPE
from app.models import MonthlyBilling, SMS_TYPE, NotificationHistory
def get_service_ids_that_need_sms_billing_populated(start_date, end_date):
return db.session.query(
NotificationHistory.service_id
).filter(
NotificationHistory.created_at >= start_date,
NotificationHistory.created_at <= end_date,
NotificationHistory.notification_type == SMS_TYPE,
NotificationHistory.billable_units != 0
).distinct().all()
def create_or_update_monthly_billing_sms(service_id, billing_month):
monthly = get_billing_data_for_month(service_id=service_id, billing_month=billing_month)
start_date, end_date = get_month_start_end_date(billing_month)
monthly = get_billing_data_for_month(service_id=service_id, start_date=start_date, end_date=end_date)
# update monthly
monthly_totals = _monthly_billing_data_to_json(monthly)
row = MonthlyBilling.query.filter_by(year=billing_month.year,

View File

@@ -36,8 +36,7 @@ def get_yearly_billing_data(service_id, year):
@statsd(namespace="dao")
def get_billing_data_for_month(service_id, billing_month):
start_date, end_date = get_month_start_end_date(billing_month)
def get_billing_data_for_month(service_id, start_date, end_date):
rates = get_rates_for_year(start_date, end_date, SMS_TYPE)
result = []
# so the start end date in the query are the valid from the rate, not the month - this is going to take some thought