Keep track of Former Members in member table status
This commit is contained in:
parent
832397ec20
commit
1924ea9399
|
@ -101,8 +101,6 @@ class TransactionSerializer(serializers.ModelSerializer):
|
|||
|
||||
# member viewing other members
|
||||
class OtherMemberSerializer(serializers.ModelSerializer):
|
||||
status = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = models.Member
|
||||
fields = [
|
||||
|
@ -117,13 +115,9 @@ class OtherMemberSerializer(serializers.ModelSerializer):
|
|||
'public_bio',
|
||||
]
|
||||
|
||||
def get_status(self, obj):
|
||||
return 'Former Member' if obj.paused_date else obj.status
|
||||
|
||||
|
||||
# member viewing his own details
|
||||
class MemberSerializer(serializers.ModelSerializer):
|
||||
status = serializers.SerializerMethodField()
|
||||
photo = serializers.ImageField(write_only=True, required=False)
|
||||
crop = serializers.CharField(write_only=True, required=False)
|
||||
email = fields.UserEmailField(serializers.EmailField)
|
||||
|
@ -166,9 +160,6 @@ class MemberSerializer(serializers.ModelSerializer):
|
|||
'trotec_cert_date',
|
||||
]
|
||||
|
||||
def get_status(self, obj):
|
||||
return 'Former Member' if obj.paused_date else obj.status
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
if instance.user:
|
||||
instance.user.email = validated_data.get('email', instance.user.email)
|
||||
|
|
|
@ -137,76 +137,67 @@ class TestCalcStatus(TestCase):
|
|||
def test_calc_member_status_14_days(self):
|
||||
expire_date = utils.today_alberta_tz() + datetime.timedelta(days=14)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Current')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_1_month(self):
|
||||
today = datetime.date(2019, 2, 10)
|
||||
expire_date = datetime.date(2019, 3, 10)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date, today)
|
||||
status = utils.calc_member_status(expire_date, today)
|
||||
|
||||
self.assertEqual(status, 'Current')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_90_days(self):
|
||||
expire_date = utils.today_alberta_tz() + datetime.timedelta(days=90)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Prepaid')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_tomorrow(self):
|
||||
expire_date = utils.today_alberta_tz() + datetime.timedelta(days=1)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Current')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_today(self):
|
||||
expire_date = utils.today_alberta_tz()
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Due')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_yesterday(self):
|
||||
expire_date = utils.today_alberta_tz() - datetime.timedelta(days=1)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Due')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_1_month_ago(self):
|
||||
today = datetime.date(2019, 4, 10)
|
||||
expire_date = datetime.date(2019, 3, 10)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date, today)
|
||||
status = utils.calc_member_status(expire_date, today)
|
||||
|
||||
self.assertEqual(status, 'Overdue')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_85_days_ago(self):
|
||||
expire_date = utils.today_alberta_tz() - datetime.timedelta(days=85)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Overdue')
|
||||
self.assertEqual(former, False)
|
||||
|
||||
def test_calc_member_status_95_days_ago(self):
|
||||
expire_date = utils.today_alberta_tz() - datetime.timedelta(days=95)
|
||||
|
||||
status, former = utils.calc_member_status(expire_date)
|
||||
status = utils.calc_member_status(expire_date)
|
||||
|
||||
self.assertEqual(status, 'Overdue')
|
||||
self.assertEqual(former, True)
|
||||
self.assertEqual(status, 'Former Member')
|
||||
|
||||
|
||||
class TestFakeMonths(TestCase):
|
||||
|
@ -354,7 +345,7 @@ class TestTallyMembership(TestCase):
|
|||
|
||||
self.assertEqual(member.expire_date, end_date)
|
||||
self.assertEqual(member.paused_date, end_date)
|
||||
self.assertEqual(member.status, 'Overdue')
|
||||
self.assertEqual(member.status, 'Former Member')
|
||||
|
||||
def test_tally_membership_months_dont_run(self):
|
||||
member = self.get_member_clear_transactions()
|
||||
|
|
|
@ -53,22 +53,22 @@ def num_months_difference(d1, d2):
|
|||
|
||||
def calc_member_status(expire_date, fake_date=None):
|
||||
'''
|
||||
Return: status, if we should pause them
|
||||
Return: member status
|
||||
'''
|
||||
today = fake_date or today_alberta_tz()
|
||||
|
||||
difference = num_months_difference(expire_date, today)
|
||||
|
||||
if today + timedelta(days=29) < expire_date:
|
||||
return 'Prepaid', False
|
||||
return 'Prepaid'
|
||||
elif difference <= -3:
|
||||
return 'Overdue', True
|
||||
return 'Former Member'
|
||||
elif today - timedelta(days=29) >= expire_date:
|
||||
return 'Overdue', False
|
||||
return 'Overdue'
|
||||
elif today < expire_date:
|
||||
return 'Current', False
|
||||
return 'Current'
|
||||
elif today >= expire_date:
|
||||
return 'Due', False
|
||||
return 'Due'
|
||||
else:
|
||||
raise()
|
||||
|
||||
|
@ -126,12 +126,12 @@ def tally_membership_months(member, fake_date=None):
|
|||
total_months = total_months_agg['number_of_membership_months__sum'] or 0
|
||||
|
||||
expire_date = add_months(start_date, total_months)
|
||||
status, former = calc_member_status(expire_date, fake_date)
|
||||
status = calc_member_status(expire_date, fake_date)
|
||||
|
||||
member.expire_date = expire_date
|
||||
member.status = status
|
||||
|
||||
if former:
|
||||
if status == 'Former Member':
|
||||
member.paused_date = expire_date
|
||||
|
||||
member.save()
|
||||
|
|
|
@ -131,6 +131,7 @@ class MemberViewSet(Base, Retrieve, Update):
|
|||
if not is_admin_director(self.request.user):
|
||||
raise exceptions.PermissionDenied()
|
||||
member = self.get_object()
|
||||
member.status = 'Former Member'
|
||||
member.paused_date = utils.today_alberta_tz()
|
||||
member.save()
|
||||
return Response(200)
|
||||
|
|
Loading…
Reference in New Issue
Block a user