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:
James Polley 2017-12-31 17:19:58 +11:00
parent d4ca04bada
commit 9dc2ea4439

View file

@ -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,