|
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|
import datetime
|
|
import datetime
|
|
from dateutil.relativedelta import relativedelta
|
|
from dateutil.relativedelta import relativedelta
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
+from django.db.models import Max
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
|
|
|
|
from coin.utils import respect_language
|
|
from coin.utils import respect_language
|
|
@@ -27,22 +28,23 @@ class Command(BaseCommand):
|
|
raise CommandError(
|
|
raise CommandError(
|
|
'Please enter a valid date : YYYY-mm-dd (ex: 2011-07-04)')
|
|
'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):
|
|
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()
|