Make sure we update the correct month for billing:

When populating the monthly billing records on a schedule, we need
to ensure the correct month is being updated.

As an example, if the current datetime is 31 Mar 2016, 23:00. The
BST equivalent is the 1st April. Therefore we need to ensure we
update billing for April, not March. This takes care of that.
This commit is contained in:
Imdad Ahad
2017-08-10 16:37:30 +01:00
parent 782f3ea693
commit 63e1167098
3 changed files with 99 additions and 25 deletions

View File

@@ -6,9 +6,13 @@ from app.dao.jobs_dao import dao_create_job
from app.dao.service_inbound_api_dao import save_service_inbound_api
from app.models import (
ApiKey,
EMAIL_TYPE,
SMS_TYPE,
KEY_TYPE_NORMAL,
Service,
User,
Template,
MonthlyBilling,
Notification,
ScheduledNotification,
ServicePermission,
@@ -17,10 +21,8 @@ from app.models import (
InboundSms,
InboundNumber,
Organisation,
EMAIL_TYPE,
SMS_TYPE,
KEY_TYPE_NORMAL,
ServiceInboundApi)
ServiceInboundApi
)
from app.dao.users_dao import save_model_user
from app.dao.notifications_dao import dao_create_notification, dao_created_scheduled_notification
from app.dao.templates_dao import dao_create_template
@@ -258,7 +260,12 @@ def create_organisation(colour='blue', logo='test_x2.png', name='test_org_1'):
def create_rate(start_date, value, notification_type):
rate = Rate(id=uuid.uuid4(), valid_from=start_date, rate=value, notification_type=notification_type)
rate = Rate(
id=uuid.uuid4(),
valid_from=start_date,
rate=value,
notification_type=notification_type
)
db.session.add(rate)
db.session.commit()
return rate
@@ -290,3 +297,24 @@ def create_inbound_number(number, provider='mmg', active=True, service_id=None):
db.session.add(inbound_number)
db.session.commit()
return inbound_number
def create_monthly_billing_entry(
service,
start_date,
end_date,
notification_type,
monthly_totals=[]
):
entry = MonthlyBilling(
service_id=service.id,
notification_type=notification_type,
monthly_totals=monthly_totals,
start_date=start_date,
end_date=end_date
)
db.session.add(entry)
db.session.commit()
return entry