Merge branch 'chrisjrn/20160913-bugs'

This commit is contained in:
Christopher Neugebauer 2016-09-13 13:33:45 +10:00
commit d5295e07a9
4 changed files with 22 additions and 9 deletions

View file

@ -205,12 +205,12 @@ class CartController(object):
to_add = sum(i[1] for i in by_cat[category]) to_add = sum(i[1] for i in by_cat[category])
if to_add > limit: if to_add > limit:
errors.append(( message_base = "You may only add %d items from category: %s"
category, message = message_base % (
"You may only have %d items in category: %s" % (
limit, category.name, limit, category.name,
) )
)) for product, quantity in by_cat[category]:
errors.append((product, message))
# Test the flag conditions # Test the flag conditions
errs = FlagController.test_flags( errs = FlagController.test_flags(

View file

@ -84,7 +84,7 @@ class ItemController(object):
aggregating like products from across multiple invoices. aggregating like products from across multiple invoices.
''' '''
return self._items(commerce.Cart.STATUS_PAID) return self._items(commerce.Cart.STATUS_PAID, category=category)
def items_pending(self): def items_pending(self):
''' Gets all of the items that the user has reserved, but has not yet ''' Gets all of the items that the user has reserved, but has not yet

View file

@ -18,6 +18,10 @@ from reports import Report
from reports import report_view from reports import report_view
def CURRENCY():
return models.DecimalField(decimal_places=2)
@user_passes_test(views._staff_only) @user_passes_test(views._staff_only)
def reports_list(request): def reports_list(request):
''' Lists all of the reports currently available. ''' ''' Lists all of the reports currently available. '''
@ -101,7 +105,9 @@ def reconciliation(request, form):
invoice__status=commerce.Invoice.STATUS_PAID, invoice__status=commerce.Invoice.STATUS_PAID,
).values( ).values(
"price", "quantity" "price", "quantity"
).aggregate(total=Sum(F("price") * F("quantity"))) ).aggregate(
total=Sum(F("price") * F("quantity"), output_field=CURRENCY()),
)
data.append(["Paid items", sales["total"]]) data.append(["Paid items", sales["total"]])

View file

@ -826,6 +826,10 @@ def amend_registration(request, user_id):
prefix="products", prefix="products",
) )
for item, form in zip(items, formset):
queryset = inventory.Product.objects.filter(id=item.product.id)
form.fields["product"].queryset = queryset
voucher_form = forms.VoucherForm( voucher_form = forms.VoucherForm(
request.POST or None, request.POST or None,
prefix="voucher", prefix="voucher",
@ -847,10 +851,13 @@ def amend_registration(request, user_id):
for ve_field in ve.error_list: for ve_field in ve.error_list:
product, message = ve_field.message product, message = ve_field.message
for form in formset: for form in formset:
if "product" not in form.cleaned_data:
# This is the empty form.
continue
if form.cleaned_data["product"] == product: if form.cleaned_data["product"] == product:
form.add_error("quantity", message) form.add_error("quantity", message)
if request.POST and voucher_form.is_valid(): if request.POST and voucher_form.has_changed() and voucher_form.is_valid():
try: try:
current_cart.apply_voucher(voucher_form.cleaned_data["voucher"]) current_cart.apply_voucher(voucher_form.cleaned_data["voucher"])
return redirect(amend_registration, user_id) return redirect(amend_registration, user_id)