Skip to content

Commit b9760ad

Browse files
committed
Fix redirection to thank you when service is free
1 parent 79df4a5 commit b9760ad

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

appointment/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ def is_paid(self):
542542
return True
543543
return self.paid
544544

545+
def service_is_paid(self):
546+
return self.get_service_price() != 0
547+
545548
def is_paid_text(self):
546549
return _("Yes") if self.is_paid() else _("No")
547550

appointment/utils/db_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def parse_name(name: str):
240240
def create_user_with_email(client_data: dict):
241241
CLIENT_MODEL = get_user_model()
242242
# Valid fields
243-
valid_fields = ['email', 'first_name', 'last_name', 'username']
243+
valid_fields = ['email', 'first_name', 'last_name']
244244

245245
# Filter client_data to include only valid fields
246246
user_data = {field: client_data.get(field, '') for field in valid_fields}

appointment/views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,17 @@ def redirect_to_payment_or_thank_you_page(appointment):
265265
:param appointment: The Appointment instance.
266266
:return: The redirect response.
267267
"""
268-
if APPOINTMENT_PAYMENT_URL is not None and APPOINTMENT_PAYMENT_URL != '':
268+
if (APPOINTMENT_PAYMENT_URL is not None and APPOINTMENT_PAYMENT_URL != '') and appointment.service_is_paid():
269269
payment_url = create_payment_info_and_get_url(appointment)
270270
return HttpResponseRedirect(payment_url)
271-
elif APPOINTMENT_THANK_YOU_URL is not None and APPOINTMENT_THANK_YOU_URL != '':
272-
thank_you_url = reverse(APPOINTMENT_THANK_YOU_URL, kwargs={'appointment_id': appointment.id})
273-
return HttpResponseRedirect(thank_you_url)
274271
else:
275-
# Redirect to your default thank you page and pass the appointment object ID
276-
return HttpResponseRedirect(
277-
reverse('appointment:default_thank_you', kwargs={'appointment_id': appointment.id})
278-
)
272+
# Determine the correct thank-you URL based on whether APPOINTMENT_THANK_YOU_URL is provided and not empty
273+
thank_you_url_key = 'appointment:default_thank_you'
274+
if APPOINTMENT_THANK_YOU_URL:
275+
thank_you_url_key = APPOINTMENT_THANK_YOU_URL
276+
277+
thank_you_url = reverse(thank_you_url_key, kwargs={'appointment_id': appointment.id})
278+
return HttpResponseRedirect(thank_you_url)
279279

280280

281281
def create_appointment(request, appointment_request_obj, client_data, appointment_data):

0 commit comments

Comments
 (0)