Voucher form needs to be processed first
Because otherwise, the firstform (which will not be in a valid start) throws errors which prevent the voucher form from ever being processed.
This commit is contained in:
parent
d4ca04bada
commit
9dc2ea4439
1 changed files with 13 additions and 12 deletions
25
vendor/registrasion/registrasion/views.py
vendored
25
vendor/registrasion/registrasion/views.py
vendored
|
@ -986,6 +986,19 @@ def amend_registration(request, user_id):
|
|||
user = User.objects.get(id=int(user_id))
|
||||
current_cart = CartController.for_user(user)
|
||||
|
||||
voucher_form = forms.VoucherForm(
|
||||
request.POST or None,
|
||||
prefix="voucher",
|
||||
)
|
||||
|
||||
if request.POST and voucher_form.has_changed() and voucher_form.is_valid():
|
||||
try:
|
||||
current_cart.apply_voucher(voucher_form.cleaned_data["voucher"])
|
||||
return redirect(amend_registration, user_id)
|
||||
except ValidationError as ve:
|
||||
voucher_form.add_error(None, ve)
|
||||
|
||||
|
||||
items = commerce.ProductItem.objects.filter(
|
||||
cart=current_cart.cart,
|
||||
).select_related("product")
|
||||
|
@ -1002,11 +1015,6 @@ def amend_registration(request, user_id):
|
|||
queryset = inventory.Product.objects.filter(id=item.product.id)
|
||||
form.fields["product"].queryset = queryset
|
||||
|
||||
voucher_form = forms.VoucherForm(
|
||||
request.POST or None,
|
||||
prefix="voucher",
|
||||
)
|
||||
|
||||
if request.POST and formset.is_valid():
|
||||
|
||||
pq = [
|
||||
|
@ -1029,13 +1037,6 @@ def amend_registration(request, user_id):
|
|||
if form.cleaned_data["product"] == product:
|
||||
form.add_error("quantity", message)
|
||||
|
||||
if request.POST and voucher_form.has_changed() and voucher_form.is_valid():
|
||||
try:
|
||||
current_cart.apply_voucher(voucher_form.cleaned_data["voucher"])
|
||||
return redirect(amend_registration, user_id)
|
||||
except ValidationError as ve:
|
||||
voucher_form.add_error(None, ve)
|
||||
|
||||
ic = ItemController(user)
|
||||
data = {
|
||||
"user": user,
|
||||
|
|
Loading…
Reference in a new issue