Commit 1bf71df3 authored by Fabs's avatar Fabs
Browse files

Improve members request for call for membership fees

parent 0f03f89d
......@@ -5,10 +5,12 @@ import datetime
from dateutil.relativedelta import relativedelta
from 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):
'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(
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():
'Send call for membership fees email to %s' % fee.member)
'Call for membership fees email was sent to %s' % member)
self.stdout.write('%d call for membership fees emails were sent' % cpt)
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