Skip to content

Commit

Permalink
fix(roster): no 1st pay after one_semester_date
Browse files Browse the repository at this point in the history
For invoices created after self.semester.one_semester_date
there shouldn't be any first_payment_deadline
  • Loading branch information
vEnhance committed Dec 13, 2024
1 parent d81da8b commit a572385
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
18 changes: 12 additions & 6 deletions roster/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ def payment_status(self):
0: student is clear (no invoice exists or total owed is nonpositive)
1: remind of upcoming payment for initial deadline
2: warn of late payment for initial deadline
3: lock late payment for initial deadline
3: lock late payment for initial deadline (more than 1 week past)
4: no warning yet, but student has something owed
5: remind of upcoming payment for primary deadline
6: warn of late payment for primary deadline
7: lock late payment for primary deadline
7: lock late payment for primary deadline (more than 1 week past)
"""
if self.semester.show_invoices is False:
return 0
Expand All @@ -298,10 +298,17 @@ def payment_status(self):

now = localtime()

first_payment_deadline = self.semester.first_payment_deadline
if (
self.semester.one_semester_date is not None
and self.semester.most_payment_deadline
and invoice.created_at > self.semester.one_semester_date
):
initial_payment_deadline = self.semester.most_payment_deadline
else:
initial_payment_deadline = self.semester.first_payment_deadline

if first_payment_deadline is not None and invoice.total_paid <= 0:
d = max(invoice.created_at, first_payment_deadline) - now
if initial_payment_deadline is not None and invoice.total_paid <= 0:
d = max(invoice.created_at, initial_payment_deadline) - now
if d < timedelta(days=-7):
return 3
elif d < timedelta(days=0):
Expand All @@ -310,7 +317,6 @@ def payment_status(self):
return 1

most_payment_deadline = self.semester.most_payment_deadline

if (
most_payment_deadline is not None
and invoice.total_paid < 2 * invoice.total_cost / 3
Expand Down
41 changes: 41 additions & 0 deletions roster/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,47 @@ def test_delinquency(self) -> None:
self.assertEqual(bob.payment_status, 7)
self.assertTrue(bob.is_delinquent)

def test_delinquency_for_joining_second_semester(self) -> None:
semester: Semester = SemesterFactory.create(
show_invoices=True,
first_payment_deadline=datetime.datetime(2022, 9, 21, tzinfo=UTC),
most_payment_deadline=datetime.datetime(2023, 1, 21, tzinfo=UTC),
one_semester_date=datetime.datetime(2022, 12, 30, tzinfo=UTC),
)

alice: Student = StudentFactory.create(semester=semester)
bob: Student = StudentFactory.create(semester=semester)
self.assertEqual(alice.payment_status, 0) # because no invoice exists
self.assertEqual(bob.payment_status, 0) # because no invoice exists
with freeze_time("2022-08-05", tz_offset=0):
InvoiceFactory.create(student=alice, preps_taught=2)
with freeze_time("2023-01-01", tz_offset=0):
InvoiceFactory.create(student=bob, preps_taught=1)

with freeze_time("2023-01-02", tz_offset=0):
self.assertEqual(alice.payment_status, 3)
self.assertTrue(alice.is_delinquent)
self.assertEqual(bob.payment_status, 4)
self.assertFalse(bob.is_delinquent)

with freeze_time("2023-01-20", tz_offset=0):
self.assertEqual(alice.payment_status, 3)
self.assertTrue(alice.is_delinquent)
self.assertEqual(bob.payment_status, 1)
self.assertFalse(bob.is_delinquent)

with freeze_time("2023-01-25", tz_offset=0):
self.assertEqual(alice.payment_status, 3)
self.assertTrue(alice.is_delinquent)
self.assertEqual(bob.payment_status, 2)
self.assertFalse(bob.is_delinquent)

with freeze_time("2023-01-30", tz_offset=0):
self.assertEqual(alice.payment_status, 3)
self.assertTrue(alice.is_delinquent)
self.assertEqual(bob.payment_status, 3)
self.assertTrue(bob.is_delinquent)

def test_student_properties(self) -> None:
alice: Student = StudentFactory.create()
units: list[Unit] = UnitFactory.create_batch(10)
Expand Down

0 comments on commit a572385

Please sign in to comment.