Keep track of Former Members in member table status

This commit is contained in:
Tanner Collin 2021-06-05 01:20:11 +00:00
parent 832397ec20
commit 1924ea9399
4 changed files with 20 additions and 37 deletions

View File

@ -101,8 +101,6 @@ class TransactionSerializer(serializers.ModelSerializer):
# member viewing other members # member viewing other members
class OtherMemberSerializer(serializers.ModelSerializer): class OtherMemberSerializer(serializers.ModelSerializer):
status = serializers.SerializerMethodField()
class Meta: class Meta:
model = models.Member model = models.Member
fields = [ fields = [
@ -117,13 +115,9 @@ class OtherMemberSerializer(serializers.ModelSerializer):
'public_bio', 'public_bio',
] ]
def get_status(self, obj):
return 'Former Member' if obj.paused_date else obj.status
# member viewing his own details # member viewing his own details
class MemberSerializer(serializers.ModelSerializer): class MemberSerializer(serializers.ModelSerializer):
status = serializers.SerializerMethodField()
photo = serializers.ImageField(write_only=True, required=False) photo = serializers.ImageField(write_only=True, required=False)
crop = serializers.CharField(write_only=True, required=False) crop = serializers.CharField(write_only=True, required=False)
email = fields.UserEmailField(serializers.EmailField) email = fields.UserEmailField(serializers.EmailField)
@ -166,9 +160,6 @@ class MemberSerializer(serializers.ModelSerializer):
'trotec_cert_date', 'trotec_cert_date',
] ]
def get_status(self, obj):
return 'Former Member' if obj.paused_date else obj.status
def update(self, instance, validated_data): def update(self, instance, validated_data):
if instance.user: if instance.user:
instance.user.email = validated_data.get('email', instance.user.email) instance.user.email = validated_data.get('email', instance.user.email)

View File

@ -137,76 +137,67 @@ class TestCalcStatus(TestCase):
def test_calc_member_status_14_days(self): def test_calc_member_status_14_days(self):
expire_date = utils.today_alberta_tz() + datetime.timedelta(days=14) 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(status, 'Current')
self.assertEqual(former, False)
def test_calc_member_status_1_month(self): def test_calc_member_status_1_month(self):
today = datetime.date(2019, 2, 10) today = datetime.date(2019, 2, 10)
expire_date = datetime.date(2019, 3, 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(status, 'Current')
self.assertEqual(former, False)
def test_calc_member_status_90_days(self): def test_calc_member_status_90_days(self):
expire_date = utils.today_alberta_tz() + datetime.timedelta(days=90) 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(status, 'Prepaid')
self.assertEqual(former, False)
def test_calc_member_status_tomorrow(self): def test_calc_member_status_tomorrow(self):
expire_date = utils.today_alberta_tz() + datetime.timedelta(days=1) 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(status, 'Current')
self.assertEqual(former, False)
def test_calc_member_status_today(self): def test_calc_member_status_today(self):
expire_date = utils.today_alberta_tz() 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(status, 'Due')
self.assertEqual(former, False)
def test_calc_member_status_yesterday(self): def test_calc_member_status_yesterday(self):
expire_date = utils.today_alberta_tz() - datetime.timedelta(days=1) 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(status, 'Due')
self.assertEqual(former, False)
def test_calc_member_status_1_month_ago(self): def test_calc_member_status_1_month_ago(self):
today = datetime.date(2019, 4, 10) today = datetime.date(2019, 4, 10)
expire_date = datetime.date(2019, 3, 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(status, 'Overdue')
self.assertEqual(former, False)
def test_calc_member_status_85_days_ago(self): def test_calc_member_status_85_days_ago(self):
expire_date = utils.today_alberta_tz() - datetime.timedelta(days=85) 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(status, 'Overdue')
self.assertEqual(former, False)
def test_calc_member_status_95_days_ago(self): def test_calc_member_status_95_days_ago(self):
expire_date = utils.today_alberta_tz() - datetime.timedelta(days=95) 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(status, 'Former Member')
self.assertEqual(former, True)
class TestFakeMonths(TestCase): class TestFakeMonths(TestCase):
@ -354,7 +345,7 @@ class TestTallyMembership(TestCase):
self.assertEqual(member.expire_date, end_date) self.assertEqual(member.expire_date, end_date)
self.assertEqual(member.paused_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): def test_tally_membership_months_dont_run(self):
member = self.get_member_clear_transactions() member = self.get_member_clear_transactions()

View File

@ -53,22 +53,22 @@ def num_months_difference(d1, d2):
def calc_member_status(expire_date, fake_date=None): 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() today = fake_date or today_alberta_tz()
difference = num_months_difference(expire_date, today) difference = num_months_difference(expire_date, today)
if today + timedelta(days=29) < expire_date: if today + timedelta(days=29) < expire_date:
return 'Prepaid', False return 'Prepaid'
elif difference <= -3: elif difference <= -3:
return 'Overdue', True return 'Former Member'
elif today - timedelta(days=29) >= expire_date: elif today - timedelta(days=29) >= expire_date:
return 'Overdue', False return 'Overdue'
elif today < expire_date: elif today < expire_date:
return 'Current', False return 'Current'
elif today >= expire_date: elif today >= expire_date:
return 'Due', False return 'Due'
else: else:
raise() 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 total_months = total_months_agg['number_of_membership_months__sum'] or 0
expire_date = add_months(start_date, total_months) 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.expire_date = expire_date
member.status = status member.status = status
if former: if status == 'Former Member':
member.paused_date = expire_date member.paused_date = expire_date
member.save() member.save()

View File

@ -131,6 +131,7 @@ class MemberViewSet(Base, Retrieve, Update):
if not is_admin_director(self.request.user): if not is_admin_director(self.request.user):
raise exceptions.PermissionDenied() raise exceptions.PermissionDenied()
member = self.get_object() member = self.get_object()
member.status = 'Former Member'
member.paused_date = utils.today_alberta_tz() member.paused_date = utils.today_alberta_tz()
member.save() member.save()
return Response(200) return Response(200)