Skip to content
Snippets Groups Projects
Commit 1c13e7fd authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch '68-skip-payment-step-when-costs-are-0-for-an-event' into 'master'

Resolve "Skip payment step when costs are 0 for an event"

Closes #68

See merge request !70
parents b8fdf82b 090cd0a9
No related branches found
No related tags found
1 merge request!70Resolve "Skip payment step when costs are 0 for an event"
Pipeline #194054 passed
......@@ -24,6 +24,7 @@ register_forms = [
condition_dict = {
"email": views.is_email_needed,
"register": views.is_person_anonymous,
"financial": views.is_financial_needed,
}
account_forms = [
......
......@@ -285,6 +285,9 @@ def set_email_needed(request, slug: Optional[str] = None):
def is_email_needed(wizard):
return wizard.request.session.get("email_needed", None)
def is_financial_needed(wizard):
return wizard.request.session.get("financial_needed", None)
TEMPLATES = {
"email": "paweljong/event/register_wizard.html",
......@@ -407,7 +410,10 @@ class RegisterEventWizardView(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super().get_context_data(form, **kwargs)
context["event"] = Event.objects.get(slug=self.kwargs["slug"])
event = Event.objects.get(slug=self.kwargs["slug"])
context["event"] = event
self.request.session["financial_needed"] = event.cost > 0
if self.steps.current == "email":
context["info_title"] = _("Create e-mail address")
......@@ -560,21 +566,15 @@ class RegisterEventWizardView(SessionWizardView):
except KeyError: # FIXME
cleaned_data_register = False
cleaned_data_additional = self.get_cleaned_data_for_step("additional")
cleaned_data_financial = self.get_cleaned_data_for_step("financial")
cleaned_data_consent = self.get_cleaned_data_for_step("consent")
if cleaned_data_financial["voucher_code"]:
if getattr(self.request.user, "person", None):
vouchers = Voucher.objects.filter(
person=self.request.user.person,
event=event,
used=False,
code=cleaned_data_financial["voucher_code"],
)
if vouchers:
voucher = vouchers.first()
else:
messages.error(self.request, _("You entered an invalid voucher code!"))
donation = 0
if is_financial_needed(self):
cleaned_data_financial = self.get_cleaned_data_for_step("financial")
donation = cleaned_data_financial["donation"]
cleaned_data_consent = self.get_cleaned_data_for_step("consent")
# Create email address
if cleaned_data_email:
......@@ -653,7 +653,7 @@ class RegisterEventWizardView(SessionWizardView):
event=event,
person=person,
medical_information=cleaned_data_additional["medical_information"],
donation=cleaned_data_financial["donation"],
donation=donation,
school=cleaned_data_contact_details["school"],
school_class=cleaned_data_contact_details["school_class"],
school_place=cleaned_data_contact_details["school_place"],
......@@ -672,23 +672,24 @@ class RegisterEventWizardView(SessionWizardView):
registration.save()
if cleaned_data_financial["voucher_code"]:
vouchers = Voucher.objects.filter(
person=person, event=event, used=False, code=cleaned_data_financial["voucher_code"]
)
if vouchers:
voucher = vouchers.first()
registration.voucher = voucher
voucher.used = True
with reversion.create_revision():
voucher.save()
registration.save()
else:
messages.error(self.request, _("You entered an invalid voucher code!"))
if is_financial_needed(self):
if cleaned_data_financial["voucher_code"]:
vouchers = Voucher.objects.filter(
person=person, event=event, used=False, code=cleaned_data_financial["voucher_code"]
)
if vouchers:
voucher = vouchers.first()
registration.voucher = voucher
voucher.used = True
with reversion.create_revision():
voucher.save()
registration.save()
else:
messages.error(self.request, _("You entered an invalid voucher code!"))
invoice = registration.get_invoice()
invoice.variant = cleaned_data_financial["payment_method"]
invoice.save()
invoice = registration.get_invoice()
invoice.variant = cleaned_data_financial["payment_method"]
invoice.save()
context = {}
context["registration"] = registration
......@@ -723,7 +724,10 @@ class RegisterEventWizardView(SessionWizardView):
user=person,
)
return redirect("do_payment", invoice.token)
if is_financial_needed(self):
return redirect("do_payment", invoice.token)
else:
return redirect("vue_app")
class EventFullView(PermissionRequiredMixin, DetailView):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment