|
@@ -5,10 +5,12 @@ import datetime
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
from django.conf import settings
|
|
|
+from django.db.models import Max
|
|
|
|
|
|
from coin.utils import respect_language
|
|
|
from coin.members.models import Member, MembershipFee
|
|
|
|
|
|
+
|
|
|
class Command(BaseCommand):
|
|
|
args = '[date=2011-07-04]'
|
|
|
help = """Send a call for membership email to members.
|
|
@@ -27,7 +29,8 @@ 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
|
|
|
+ # 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),
|
|
@@ -37,12 +40,15 @@ class Command(BaseCommand):
|
|
|
self.stdout.write(
|
|
|
'Select membership fees for following end dates : %s' % call_dates)
|
|
|
|
|
|
- fees = MembershipFee.objects.filter(end_date__in=call_dates)
|
|
|
+ members = Member.objects.annotate(end_date_membership=Max(
|
|
|
+ 'membership_fees__end_date')).filter(end_date_membership__in=call_dates)
|
|
|
|
|
|
+ cpt = 0
|
|
|
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)):
|
|
|
+ for member in members:
|
|
|
+ if member.send_call_for_membership_fees_email():
|
|
|
self.stdout.write(
|
|
|
- 'Send call for membership fees email to %s' % fee.member)
|
|
|
- fee.member.send_call_for_membership_fees_email()
|
|
|
+ 'Call for membership fees email was sent to %s' % member)
|
|
|
+ cpt=cpt+1
|
|
|
+
|
|
|
+ self.stdout.write('%d call for membership fees emails were sent' % cpt)
|