mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
- Add update dao_update_annual_billing_for_current_and_future_years
- moved get_current_financial_year_start_year from service.utils to dao.date_utils - Moved logic for data persistence from rest to dao when updating records in db
This commit is contained in:
@@ -4,8 +4,24 @@ from app.dao.dao_utils import (
|
||||
version_class
|
||||
)
|
||||
from app.models import AnnualBilling
|
||||
from datetime import datetime
|
||||
from app.service.utils import get_current_financial_year_start_year
|
||||
from app.dao.date_util import get_current_financial_year_start_year
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_create_or_update_annual_billing_for_year(service_id, free_sms_fragment_limit, financial_year_start=None):
|
||||
|
||||
if not financial_year_start:
|
||||
financial_year_start = get_current_financial_year_start_year()
|
||||
|
||||
result = dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start)
|
||||
|
||||
if result:
|
||||
result.free_sms_fragment_limit = free_sms_fragment_limit
|
||||
else:
|
||||
result = AnnualBilling(service_id=service_id, financial_year_start=financial_year_start,
|
||||
free_sms_fragment_limit=free_sms_fragment_limit)
|
||||
db.session.add(result)
|
||||
return result
|
||||
|
||||
|
||||
def dao_get_annual_billing(service_id):
|
||||
@@ -14,16 +30,28 @@ def dao_get_annual_billing(service_id):
|
||||
).order_by(AnnualBilling.financial_year_start).all()
|
||||
|
||||
|
||||
def dao_create_or_update_annual_billing_for_year(annual_billing):
|
||||
db.session.add(annual_billing)
|
||||
db.session.commit()
|
||||
@transactional
|
||||
def dao_update_annual_billing_for_current_and_future_years(service_id, free_sms_fragment_limit,
|
||||
financial_year_start=None):
|
||||
if not financial_year_start:
|
||||
financial_year_start = get_current_financial_year_start_year()
|
||||
|
||||
updated = AnnualBilling.query.filter(
|
||||
AnnualBilling.service_id == service_id,
|
||||
AnnualBilling.financial_year_start >= financial_year_start
|
||||
).update(
|
||||
{'free_sms_fragment_limit': free_sms_fragment_limit}
|
||||
)
|
||||
|
||||
|
||||
def dao_get_free_sms_fragment_limit_for_year(service_id, year):
|
||||
def dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start=None):
|
||||
|
||||
if not financial_year_start:
|
||||
financial_year_start = get_current_financial_year_start_year()
|
||||
|
||||
return AnnualBilling.query.filter_by(
|
||||
service_id=service_id,
|
||||
financial_year_start=year
|
||||
financial_year_start=financial_year_start
|
||||
).first()
|
||||
|
||||
|
||||
|
||||
@@ -45,3 +45,12 @@ def get_month_start_and_end_date_in_utc(month_year):
|
||||
first_day = datetime(month_year.year, month_year.month, 1, 0, 0, 0)
|
||||
last_day = datetime(month_year.year, month_year.month, num_days, 23, 59, 59, 99999)
|
||||
return convert_bst_to_utc(first_day), convert_bst_to_utc(last_day)
|
||||
|
||||
|
||||
def get_current_financial_year_start_year():
|
||||
now = datetime.now()
|
||||
financial_year_start = now.year
|
||||
start_date, end_date = get_financial_year(now.year)
|
||||
if now < start_date:
|
||||
financial_year_start = financial_year_start - 1
|
||||
return financial_year_start
|
||||
|
||||
Reference in New Issue
Block a user