mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Fix the logic gettting the rates for a financial year.
The is_between_end_date_exclusive is a bit funny. Perhaps the better way to handle it is to make the function is_between but change the financial year function return an enddate that is one millisecond less. That way we can always use the between logic and it will be easier to use.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Float, Integer
|
||||
from sqlalchemy import func, case, cast
|
||||
from sqlalchemy import func, case, cast, desc, between
|
||||
from sqlalchemy import literal_column
|
||||
|
||||
from app import db
|
||||
@@ -103,8 +103,25 @@ def sms_yearly_billing_data_query(rate, service_id, start_date, end_date):
|
||||
|
||||
|
||||
def get_rates_for_year(start_date, end_date, notification_type):
|
||||
return Rate.query.filter(Rate.valid_from >= start_date, Rate.valid_from < end_date,
|
||||
Rate.notification_type == notification_type).order_by(Rate.valid_from).all()
|
||||
rates = Rate.query.filter(Rate.notification_type == notification_type).order_by(Rate.valid_from).all()
|
||||
results = []
|
||||
for current_rate, current_rate_expiry_date in zip(rates, rates[1:]):
|
||||
if is_between_end_date_exclusive(current_rate.valid_from, start_date, end_date) or \
|
||||
is_between_end_date_exclusive(current_rate_expiry_date.valid_from, start_date, end_date):
|
||||
results.append(current_rate)
|
||||
|
||||
if is_between_end_date_exclusive(rates[-1].valid_from, start_date, end_date):
|
||||
results.append(rates[-1])
|
||||
|
||||
if not results:
|
||||
if start_date >= rates[-1].valid_from:
|
||||
results.append(rates[-1])
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def is_between_end_date_exclusive(date, start_date, end_date):
|
||||
return start_date <= date < end_date
|
||||
|
||||
|
||||
def sms_billing_data_per_month_query(rate, service_id, start_date, end_date):
|
||||
|
||||
Reference in New Issue
Block a user