From f5e303584bda0d33c11ae87b6b38fd976c1a7195 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 13 Sep 2016 12:27:07 +1000 Subject: [PATCH 1/6] Adds an output_field type to reconciliation sums. Fixes #75 --- registrasion/reporting/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/registrasion/reporting/views.py b/registrasion/reporting/views.py index 489a8203..962b7071 100644 --- a/registrasion/reporting/views.py +++ b/registrasion/reporting/views.py @@ -18,6 +18,10 @@ from reports import Report from reports import report_view +def CURRENCY(): + return models.DecimalField(decimal_places=2) + + @user_passes_test(views._staff_only) def reports_list(request): ''' Lists all of the reports currently available. ''' @@ -101,7 +105,9 @@ def reconciliation(request, form): invoice__status=commerce.Invoice.STATUS_PAID, ).values( "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"]]) From a27264ac92898c1d09a14536e5f76b1060b90c2c Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 13 Sep 2016 12:28:48 +1000 Subject: [PATCH 2/6] Filters items_purchased by category. Fixes #74 --- registrasion/controllers/item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registrasion/controllers/item.py b/registrasion/controllers/item.py index f2d0a2ae..9a1a9eb2 100644 --- a/registrasion/controllers/item.py +++ b/registrasion/controllers/item.py @@ -84,7 +84,7 @@ class ItemController(object): 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): ''' Gets all of the items that the user has reserved, but has not yet From 9dd31128bbbac9d4cc1f447053abb3655de14089 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 13 Sep 2016 13:19:09 +1000 Subject: [PATCH 3/6] =?UTF-8?q?Restricts=20=E2=80=98amend=E2=80=99=20produ?= =?UTF-8?q?ct=20widgets=20to=20the=20original=20product.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #76. --- registrasion/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/registrasion/views.py b/registrasion/views.py index c457295f..027dc819 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -826,6 +826,10 @@ def amend_registration(request, user_id): 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( request.POST or None, prefix="voucher", From 3903d2be56d6160f55c455b73792c44a2d871806 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 13 Sep 2016 13:19:31 +1000 Subject: [PATCH 4/6] Fixes issues on /amend --- registrasion/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/registrasion/views.py b/registrasion/views.py index 027dc819..704b05c2 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -851,10 +851,13 @@ def amend_registration(request, user_id): for ve_field in ve.error_list: product, message = ve_field.message for form in formset: + if "product" not in form.cleaned_data: + # This is the empty form. + continue if form.cleaned_data["product"] == product: 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: current_cart.apply_voucher(voucher_form.cleaned_data["voucher"]) return redirect(amend_registration, user_id) From 1c239c361f00246a21f70e4a5a61600634e1ccca Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 13 Sep 2016 13:19:53 +1000 Subject: [PATCH 5/6] Propagates the per_user_limit category error to the products, rather than the category. Fixes #79. --- registrasion/controllers/cart.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/registrasion/controllers/cart.py b/registrasion/controllers/cart.py index 9f27ab49..3e417f1a 100644 --- a/registrasion/controllers/cart.py +++ b/registrasion/controllers/cart.py @@ -205,12 +205,11 @@ class CartController(object): to_add = sum(i[1] for i in by_cat[category]) if to_add > limit: - errors.append(( - category, - "You may only have %d items in category: %s" % ( - limit, category.name, - ) - )) + message = "You may only have %d items in category: %s" % ( + limit, category.name, + ) + for product, quantity in by_cat[category]: + errors.append((product, message)) # Test the flag conditions errs = FlagController.test_flags( From 2658c2ccde510fc8ea82e3b905b64f931bf23029 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 13 Sep 2016 13:33:20 +1000 Subject: [PATCH 6/6] Improves the error message when per_user_limit on category is breached. Fixes #80 --- registrasion/controllers/cart.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/registrasion/controllers/cart.py b/registrasion/controllers/cart.py index 3e417f1a..ad4458ea 100644 --- a/registrasion/controllers/cart.py +++ b/registrasion/controllers/cart.py @@ -205,7 +205,8 @@ class CartController(object): to_add = sum(i[1] for i in by_cat[category]) if to_add > limit: - message = "You may only have %d items in category: %s" % ( + message_base = "You may only add %d items from category: %s" + message = message_base % ( limit, category.name, ) for product, quantity in by_cat[category]: