Commit 21be28e7 authored by Baptiste Jonglez's avatar Baptiste Jonglez
Browse files

Simplify the computation of members to remind about their expiring membership fee

parent b69c66e2
......@@ -94,7 +94,10 @@ Database
At this point, you should setup your database: we highly recommend PostgreSQL.
SQLite might work, but some features will not be available:
- automatic allocation of IP subnet
- automatic allocation of IP subnets (needs proper subnet implementation in
the database)
- sending automated emails to remind of expiring membership fee
(needs aggregation on date fields, see Django doc)
For more information on the database setup, see:
......
......@@ -4,6 +4,7 @@ from __future__ import unicode_literals
import datetime
from dateutil.relativedelta import relativedelta
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Max
from django.conf import settings
from coin.utils import respect_language
......@@ -27,22 +28,23 @@ class Command(BaseCommand):
raise CommandError(
'Please enter a valid date : YYYY-mm-dd (ex: 2011-07-04)')
# Get membership_fees filtered by end date of membership at specific date relative to today
call_dates = [date + relativedelta(months=-3),
date + relativedelta(months=-2),
date + relativedelta(months=-1),
date,
date + relativedelta(months=+1)]
end_dates = [date + relativedelta(months=-3),
date + relativedelta(months=-2),
date + relativedelta(months=-1),
date,
date + relativedelta(months=+1)]
self.stdout.write(
'Select membership fees for following end dates : %s' % call_dates)
self.stdout.write("Selecting members whose membership fee end at the "
"following dates : {dates}".format(
dates=[str(d) for d in end_dates]))
fees = MembershipFee.objects.filter(end_date__in=call_dates)
members = Member.objects.annotate(end=Max('membership_fees__end_date'))\
.filter(end__in=end_dates)
self.stdout.write("Got {number} members.".format(number=members.count()))
with respect_language(settings.LANGUAGE_CODE):
for fee in fees:
# Don't send if member is paid up 1 month and 1 day after today.
if not fee.member.is_paid_up(date + relativedelta(months=+1, days=+1)):
self.stdout.write(
'Send call for membership fees email to %s' % fee.member)
fee.member.send_call_for_membership_fees_email()
for member in members:
self.stdout.write(
"Sending email to {member} ({email})...".format(
member=member, email=member.email))
member.send_call_for_membership_fees_email()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment