Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated billing to send month's bills on first day of month when bill…

…ing cycle is due to end instead of 14 days before end of billing cycle
  • Loading branch information...
commit c5fa366c69882270ad2c030c923dae9980107823 1 parent 4c4fdcd
Jasse Lahdenperä KilledWhale authored
5 membership/management/commands/makebills.py
View
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import logging
from datetime import datetime, timedelta
+import calendar
from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import NoArgsCommand
@@ -90,6 +91,8 @@ def makebills():
logger.info("Running makebills...")
latest_recorded_payment = Payment.latest_payment_date()
+ dt = datetime.now()
+ last_of_month = datetime(dt.year, dt.month, calendar.monthrange(dt.year, dt.month)[1], 23, 59, 59)
for member in Membership.objects.filter(status='A').filter(id__gt=0):
# Billing cycles and bills
cycles = member.billingcycle_set
@@ -100,7 +103,7 @@ def makebills():
latest_cycle = cycles.latest("end")
if latest_cycle.end < datetime.now():
logger.warning("no new billing cycle created for %s after an expired one!" % repr(member))
- if latest_cycle.end < datetime.now() + timedelta(days=settings.BILL_DAYS_BEFORE_CYCLE):
+ if latest_cycle.end <= last_of_month:
cycle = create_billingcycle(member)
logger.info("Created billing cycle %s for %s" %
(repr(cycle), repr(member)))
8 membership/tests.py
View
@@ -9,6 +9,7 @@
from decimal import Decimal
from datetime import datetime, timedelta
from random import randint
+import calendar
import json
from django.contrib.auth.models import User
@@ -481,18 +482,19 @@ def test_new_billing_cycle_with_previous_paid(self):
self.assertEqual(len(m.billingcycle_set.all()), 1)
self.assertEqual(len(mail.outbox), 1)
+ dt = datetime.now()
c = m.billingcycle_set.all()[0]
- c.end = datetime.now() + timedelta(days=5)
+ c.end = datetime(dt.year, dt.month, calendar.monthrange(dt.year, dt.month)[1], 23, 59, 59)
c.save()
b = c.last_bill()
- b.due_date = datetime.now() + timedelta(days=9)
+ b.due_date = datetime(dt.year, dt.month, 1) + timedelta(days = 7)
b.save()
b.billingcycle.is_paid = True
b.billingcycle.save()
makebills()
- self.assertTrue(len(m.billingcycle_set.all()), 2)
+ self.assertEqual(len(m.billingcycle_set.all()), 2)
self.assertEqual(len(mail.outbox), 2)
class SingleMemberBillingModelsTest(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.