Skip to content

Commit

Permalink
fix(roster): fix bug in invoice lock logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vEnhance committed Mar 31, 2024
1 parent 7001a01 commit f13f9cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
11 changes: 3 additions & 8 deletions roster/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,8 @@ def payment_status(self):

first_payment_deadline = self.semester.first_payment_deadline

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

if (
most_payment_deadline is not None
and most_payment_deadline > invoice.created_at
and invoice.total_paid < 2 * invoice.total_cost / 3
):
d = most_payment_deadline - now
d = max(invoice.created_at, most_payment_deadline) - now
if d < timedelta(days=-7):
return 7
elif d < timedelta(days=0):
Expand Down
8 changes: 4 additions & 4 deletions roster/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ def test_delinquency(self) -> None:

bob: Student = StudentFactory.create(semester=semester)

# Bob is unaffected by earlier payment dates
# Bob gets a bit of extra time to pay because he joined recently
with freeze_time("2023-1-23", tz_offset=0):
invoice2: Invoice = InvoiceFactory.create(
student=bob,
preps_taught=1,
)
self.assertEqual(bob.payment_status, 4)
self.assertEqual(bob.payment_status, 1)
self.assertFalse(bob.is_delinquent)

# Now he is affected
Expand All @@ -227,8 +227,8 @@ def test_delinquency(self) -> None:
invoice2.save()

with freeze_time("2023-2-08", tz_offset=0):
self.assertEqual(bob.payment_status, 4)
self.assertFalse(bob.is_delinquent)
self.assertEqual(bob.payment_status, 7)
self.assertTrue(bob.is_delinquent)

semester.most_payment_deadline = datetime.datetime(
2023, 2, 21, tzinfo=timezone.utc
Expand Down

0 comments on commit f13f9cf

Please sign in to comment.