Add a fake membership transaction when importing old portal

This commit is contained in:
Tanner Collin 2020-01-19 06:58:51 +00:00
parent 0fe999ca97
commit 73b6d19c19
4 changed files with 76 additions and 29 deletions

View File

@ -136,51 +136,58 @@ class TestCalcStatus(TestCase):
def test_calc_member_status_14_days(self): def test_calc_member_status_14_days(self):
expire_date = datetime.date.today() + datetime.timedelta(days=14) expire_date = datetime.date.today() + datetime.timedelta(days=14)
status = utils.calc_member_status(expire_date) status, former = utils.calc_member_status(expire_date)
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 = datetime.date.today() + datetime.timedelta(days=90) expire_date = datetime.date.today() + datetime.timedelta(days=90)
status = utils.calc_member_status(expire_date) status, former = 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 = datetime.date.today() + datetime.timedelta(days=1) expire_date = datetime.date.today() + datetime.timedelta(days=1)
status = utils.calc_member_status(expire_date) status, former = 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 = datetime.date.today() expire_date = datetime.date.today()
status = utils.calc_member_status(expire_date) status, former = utils.calc_member_status(expire_date)
self.assertEqual(status, 'Current') self.assertEqual(status, 'Due')
self.assertEqual(former, False)
def test_calc_member_status_yesterday(self): def test_calc_member_status_yesterday(self):
expire_date = datetime.date.today() - datetime.timedelta(days=1) expire_date = datetime.date.today() - datetime.timedelta(days=1)
status = utils.calc_member_status(expire_date) status, former = utils.calc_member_status(expire_date)
self.assertEqual(status, 'Due') self.assertEqual(status, 'Due')
self.assertEqual(former, False)
def test_calc_member_status_85_days_ago(self): def test_calc_member_status_85_days_ago(self):
expire_date = datetime.date.today() - datetime.timedelta(days=85) expire_date = datetime.date.today() - datetime.timedelta(days=85)
status = utils.calc_member_status(expire_date) status, former = 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 = datetime.date.today() - datetime.timedelta(days=95) expire_date = datetime.date.today() - datetime.timedelta(days=95)
status = utils.calc_member_status(expire_date) status, former = utils.calc_member_status(expire_date)
self.assertEqual(status, 'Former Member') self.assertEqual(status, 'Overdue')
self.assertEqual(former, True)
class TestFakeMonths(TestCase): class TestFakeMonths(TestCase):
@ -308,7 +315,7 @@ class TestTallyMembership(TestCase):
self.assertEqual(member.expire_date, end_date) self.assertEqual(member.expire_date, end_date)
self.assertEqual(member.status, 'Overdue') self.assertEqual(member.status, 'Overdue')
def test_tally_membership_months_overdue(self): def test_tally_membership_months_overdue_pause(self):
member = self.get_member_clear_transactions() member = self.get_member_clear_transactions()
test_num_months = 1 test_num_months = 1
start_date = datetime.date.today() - relativedelta.relativedelta(months=6, days=14) start_date = datetime.date.today() - relativedelta.relativedelta(months=6, days=14)
@ -328,7 +335,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, 'Former Member') self.assertEqual(member.status, 'Overdue')
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

@ -20,20 +20,24 @@ def num_months_difference(d1, d2):
r = relativedelta.relativedelta(d1, d2) r = relativedelta.relativedelta(d1, d2)
return r.months + 12 * r.years return r.months + 12 * r.years
def calc_member_status(expire_date): def calc_member_status(expire_date, fake_date=None):
today = datetime.date.today() '''
Returns the member's status and if their membership should stop
'''
today = fake_date or datetime.date.today()
difference = num_months_difference(expire_date, today) difference = num_months_difference(expire_date, today)
#if today + datetime.timedelta(days=29) < expire_date:
if difference >= 1: if difference >= 1:
return 'Prepaid' return 'Prepaid', False
elif difference <= -3: elif difference <= -3:
return 'Former Member' return 'Overdue', True
elif difference <= -1: elif difference <= -1:
return 'Overdue' return 'Overdue', False
elif today <= expire_date: elif today < expire_date:
return 'Current' return 'Current', False
elif today > expire_date: elif today >= expire_date:
return 'Due' return 'Due', False
else: else:
raise() raise()
@ -70,7 +74,7 @@ def fake_missing_membership_months(member):
return tx return tx
def tally_membership_months(member): def tally_membership_months(member, fake_date=None):
''' '''
Sum together member's dues and calculate their new expire date and status Sum together member's dues and calculate their new expire date and status
Doesn't work if member is paused. Doesn't work if member is paused.
@ -78,18 +82,19 @@ def tally_membership_months(member):
if member.paused_date: return False if member.paused_date: return False
start_date = member.current_start_date start_date = member.current_start_date
if not start_date: return False
txs = models.Transaction.objects.filter(member_id=member.id) txs = models.Transaction.objects.filter(member_id=member.id)
total_months_agg = txs.aggregate(Sum('number_of_membership_months')) total_months_agg = txs.aggregate(Sum('number_of_membership_months'))
total_months = total_months_agg['number_of_membership_months__sum'] total_months = total_months_agg['number_of_membership_months__sum']
expire_date = add_months(start_date, total_months) expire_date = add_months(start_date, total_months)
status = calc_member_status(expire_date) status, former = calc_member_status(expire_date, fake_date)
member.expire_date = expire_date member.expire_date = expire_date
member.status = status member.status = status
if status == 'Former Member': if former:
member.paused_date = expire_date member.paused_date = expire_date
member.save() member.save()

View File

@ -2,7 +2,8 @@ import django, sys, os
os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings'
django.setup() django.setup()
from apiserver.api import models, old_models import datetime
from apiserver.api import models, old_models, utils
from apiserver.api.serializers import process_image from apiserver.api.serializers import process_image
MEMBER_FIELDS = [ MEMBER_FIELDS = [
@ -110,6 +111,40 @@ for o in old:
print('Deleting all transactions...') print('Deleting all transactions...')
models.Transaction.objects.all().delete() models.Transaction.objects.all().delete()
print('Faking membership months...')
members = models.Member.objects.all()
bad_count = 0
for m in members:
old_status = m.status
old_expire = m.expire_date
if not m.current_start_date: continue
if 'Former' in old_status:
m.status = 'Old Portal ' + old_status
m.save()
continue
import_date = datetime.date(2020, 1, 3)
tx = utils.fake_missing_membership_months(m)
utils.tally_membership_months(m, import_date)
print(m.first_name, m.last_name, tx.memo)
if old_status != m.status or old_expire != m.expire_date:
print('Expire mismatch member:', m.__dict__)
print('New status:', m.status)
print('Old status:', old_status)
print('Old expire:', old_expire)
bad_count += 1
print('Import mismatch count:', bad_count)
print('Pausing former members...')
for m in members:
if 'Former' in m.status:
paused_date = m.expire_date or datetime.date.today()
print('Importing old transactions...') print('Importing old transactions...')
old = old_models.Transactions.objects.using('old_portal').all() old = old_models.Transactions.objects.using('old_portal').all()
@ -125,6 +160,7 @@ for o in old:
)) ))
print('Deleting all cards...') print('Deleting all cards...')
models.Card.objects.all().delete() models.Card.objects.all().delete()
print('Importing old cards...') print('Importing old cards...')

View File

@ -100,8 +100,7 @@ function MemberInfo(props) {
}; };
export function Home(props) { export function Home(props) {
const { token, setTokenCache, user, setUserCache } = props; const { user } = props;
return ( return (
<Container> <Container>
<Grid stackable padded columns={2}> <Grid stackable padded columns={2}>
@ -110,14 +109,14 @@ export function Home(props) {
user.member.set_details ? user.member.set_details ?
<MemberInfo user={user} /> <MemberInfo user={user} />
: :
<AccountForm token={token} user={user} setUserCache={setUserCache} /> <AccountForm {...props} />
: :
<div> <div>
<LoginForm setTokenCache={setTokenCache} /> <LoginForm {...props} />
<Divider section horizontal>Or</Divider> <Divider section horizontal>Or</Divider>
<SignupForm setTokenCache={setTokenCache} /> <SignupForm {...props} />
</div> </div>
} }
</Grid.Column> </Grid.Column>