Skip to content

Commit 30261f4

Browse files
committed
Fix membership form for December
1 parent b179ac3 commit 30261f4

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

booking/forms.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,31 +378,35 @@ def __init__(self, *args, **kwargs):
378378

379379
# if current date is <25th, give option to start membership from this month as well as next monht
380380
today = datetime.today()
381+
if today.month == 12:
382+
next_month = 1
383+
else:
384+
next_month = today.month + 1
381385
if today.day < 25 and not has_cancelled_current_membership:
382386
# choice values refer to whether to backdate or not
383-
choices = ((1, calendar.month_name[today.month]), (0, calendar.month_name[today.month + 1]))
387+
choices = ((1, calendar.month_name[today.month]), (0, calendar.month_name[next_month]))
384388
initial = None
385389
help_text = (
386390
f"Note that if you choose to start your membership in the current month ({calendar.month_name[today.month]}), "
387391
f"payment will be taken immediately, and you will have the entire {calendar.month_name[today.month]} membership allowance to "
388392
f"use until the end of the month. Payment will be taken again on the 25th {calendar.month_name[today.month]} "
389-
f"for {calendar.month_name[today.month + 1]}'s membership, and on the 25th of each month thereafter."
393+
f"for {calendar.month_name[next_month]}'s membership, and on the 25th of each month thereafter."
390394
)
391395
else:
392396
# no option to backdate if it's 25th or later in the month, only show option for next month
393-
choices = ((0, calendar.month_name[today.month + 1]),)
397+
choices = ((0, calendar.month_name[next_month]),)
394398
initial = 0
395399
if today.day >= 25:
396400
help_text = (
397-
f"Payment will be taken immediately for {calendar.month_name[today.month + 1]}'s membership. You will be able to use this membership "
398-
f"immediately to book for classes scheduled in {calendar.month_name[today.month + 1]}. Payment will be taken on the 25th of each "
401+
f"Payment will be taken immediately for {calendar.month_name[next_month]}'s membership. You will be able to use this membership "
402+
f"immediately to book for classes scheduled in {calendar.month_name[next_month]}. Payment will be taken on the 25th of each "
399403
"month thereafter, for the following month's membership."
400404
)
401405
else:
402406
help_text = (
403-
f"Payment will be taken on 25th {calendar.month_name[today.month]} for {calendar.month_name[today.month + 1]}'s membership. "
407+
f"Payment will be taken on 25th {calendar.month_name[today.month]} for {calendar.month_name[next_month]}'s membership. "
404408
"You will be able to use this membership immediately to book for classes scheduled in "
405-
f"{calendar.month_name[today.month + 1]}. Payment will be taken on the 25th of each "
409+
f"{calendar.month_name[next_month]}. Payment will be taken on the 25th of each "
406410
"month thereafter, for the following month's membership."
407411
)
408412

booking/tests/test_membership_views.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ def test_membership_create_get(client, seller, configured_user):
5252
assert form.fields["backdate"].choices == [(1, "February"), (0, "March")]
5353

5454

55+
@pytest.mark.freeze_time("2024-12-10")
56+
@patch("booking.models.membership_models.StripeConnector", MockConnector)
57+
def test_membership_create_get_end_of_year(client, seller, configured_user):
58+
client.force_login(configured_user)
59+
m1 = baker.make(Membership, name="m1", active=True)
60+
m2 = baker.make(Membership, name="m2", active=True)
61+
m3 = baker.make(Membership, name="m3", active=False)
62+
baker.make(Membership, name="m4", active=True)
63+
for m in [m1, m2, m3]:
64+
baker.make(MembershipItem, membership=m)
65+
resp = client.get(create_url)
66+
assert resp.status_code == 200
67+
form = resp.context_data["form"]
68+
assert set(form.fields["membership"].queryset) == {m1, m2}
69+
assert form.fields["backdate"].choices == [(1, "December"), (0, "January")]
70+
71+
5572
@pytest.mark.freeze_time("2024-02-25 10:00")
5673
@patch("booking.models.membership_models.StripeConnector", MockConnector)
5774
def test_membership_create_after_25th_of_month(client, seller, configured_user):

0 commit comments

Comments
 (0)