Merge branch 'master' into sms_sender_id-for-post-notfications

This commit is contained in:
Rebecca Law
2017-10-30 15:20:39 +00:00
14 changed files with 426 additions and 29 deletions

View File

@@ -0,0 +1,47 @@
from app import db, create_uuid
from app.dao.dao_utils import (
transactional,
version_class
)
from app.models import AnnualBilling
from datetime import datetime
from app.service.utils import get_current_financial_year_start_year
def dao_get_annual_billing(service_id):
return AnnualBilling.query.filter_by(
service_id=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()
def dao_get_free_sms_fragment_limit_for_year(service_id, year):
return AnnualBilling.query.filter_by(
service_id=service_id,
financial_year_start=year
).first()
def dao_get_all_free_sms_fragment_limit(service_id):
return AnnualBilling.query.filter_by(
service_id=service_id,
).order_by(AnnualBilling.financial_year_start).all()
def dao_insert_annual_billing(service):
"""
This method is called from create_service which is wrapped in a transaction.
"""
annual_billing = AnnualBilling(
free_sms_fragment_limit=service.free_sms_fragment_limit,
financial_year_start=get_current_financial_year_start_year(),
service=service,
)
db.session.add(annual_billing)

View File

@@ -37,10 +37,12 @@ from app.models import (
EMAIL_TYPE,
INTERNATIONAL_SMS_TYPE,
ServiceSmsSender,
AnnualBilling
)
from app.service.statistics import format_monthly_template_notification_stats
from app.statsd_decorators import statsd
from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc
from app.dao.annual_billing_dao import dao_insert_annual_billing
DEFAULT_SERVICE_PERMISSIONS = [
SMS_TYPE,
@@ -164,6 +166,9 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
if service_permissions is None:
service_permissions = DEFAULT_SERVICE_PERMISSIONS
if service.free_sms_fragment_limit is None:
service.free_sms_fragment_limit = current_app.config['FREE_SMS_TIER_FRAGMENT_COUNT']
from app.dao.permissions_dao import permission_dao
service.users.append(user)
permission_dao.add_default_service_permissions_for_user(user, service)
@@ -176,6 +181,7 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
service.permissions.append(service_permission)
insert_service_sms_sender(service, service.sms_sender)
dao_insert_annual_billing(service)
db.session.add(service)
@@ -238,6 +244,7 @@ def delete_service_and_all_associated_db_objects(service):
_delete_commit(ServicePermission.query.filter_by(service_id=service.id))
_delete_commit(ApiKey.query.filter_by(service=service))
_delete_commit(ApiKey.get_history_model().query.filter_by(service_id=service.id))
_delete_commit(AnnualBilling.query.filter_by(service_id=service.id))
verify_codes = VerifyCode.query.join(User).filter(User.id.in_([x.id for x in service.users]))
list(map(db.session.delete, verify_codes))