Merge branch 'random_bug_fixes'

This commit is contained in:
Christopher Neugebauer 2016-04-25 17:37:42 +10:00
commit 7c86f848f1
6 changed files with 32 additions and 42 deletions

View file

@ -71,7 +71,7 @@ def available_discounts(user, categories, products):
# is not available any more. # is not available any more.
past_uses = commerce.DiscountItem.objects.filter( past_uses = commerce.DiscountItem.objects.filter(
cart__user=user, cart__user=user,
cart__status=commerce.Cart.STATUS_PAID, # Only past carts count cart__status=commerce.Cart.STATUS_PAID, # Only past carts count
discount=real_discount, discount=real_discount,
) )
agg = past_uses.aggregate(Sum("quantity")) agg = past_uses.aggregate(Sum("quantity"))

View file

@ -10,6 +10,7 @@ register = template.Library()
_ProductAndQuantity = namedtuple("ProductAndQuantity", ["product", "quantity"]) _ProductAndQuantity = namedtuple("ProductAndQuantity", ["product", "quantity"])
class ProductAndQuantity(_ProductAndQuantity): class ProductAndQuantity(_ProductAndQuantity):
''' Class that holds a product and a quantity. ''' Class that holds a product and a quantity.

View file

@ -26,12 +26,16 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
super(RegistrationCartTestCase, self).setUp() super(RegistrationCartTestCase, self).setUp()
def tearDown(self): def tearDown(self):
if False: if True:
# If you're seeing segfaults in tests, enable this. # If you're seeing segfaults in tests, enable this.
call_command('flush', verbosity=0, interactive=False, call_command(
reset_sequences=False, 'flush',
allow_cascade=False, verbosity=0,
inhibit_post_migrate=False) interactive=False,
reset_sequences=False,
allow_cascade=False,
inhibit_post_migrate=False
)
super(RegistrationCartTestCase, self).tearDown() super(RegistrationCartTestCase, self).tearDown()
@ -51,11 +55,11 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
password='top_secret') password='top_secret')
attendee1 = people.Attendee.get_instance(cls.USER_1) attendee1 = people.Attendee.get_instance(cls.USER_1)
profile1 = people.AttendeeProfileBase.objects.create( people.AttendeeProfileBase.objects.create(
attendee=attendee1, attendee=attendee1,
) )
attendee2 = people.Attendee.get_instance(cls.USER_2) attendee2 = people.Attendee.get_instance(cls.USER_2)
profile2 = people.AttendeeProfileBase.objects.create( people.AttendeeProfileBase.objects.create(
attendee=attendee2, attendee=attendee2,
) )

View file

@ -484,7 +484,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
invoice.pay("Paying into the void.", cnval, pre_validate=False) invoice.pay("Paying into the void.", cnval, pre_validate=False)
notes = commerce.CreditNote.objects.filter(invoice=invoice.invoice) notes = commerce.CreditNote.objects.filter(invoice=invoice.invoice)
notes = sorted(notes, key = lambda note: note.value) notes = sorted(notes, key=lambda note: note.value)
self.assertEqual(cnval, notes[0].value) self.assertEqual(cnval, notes[0].value)
self.assertEqual(val, notes[1].value) self.assertEqual(val, notes[1].value)

View file

@ -16,11 +16,11 @@ from collections import namedtuple
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import user_passes_test
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect from django.shortcuts import redirect
from django.shortcuts import render from django.shortcuts import render
@ -41,17 +41,17 @@ class GuidedRegistrationSection(_GuidedRegistrationSection):
''' Represents a section of a guided registration page. ''' Represents a section of a guided registration page.
Attributes: Attributes:
title (str): The title of the section. title (str): The title of the section.
discounts ([registrasion.contollers.discount.DiscountAndQuantity, ...]): discounts ([registrasion.contollers.discount.DiscountAndQuantity, ...]):
A list of discount objects that are available in the section. You A list of discount objects that are available in the section. You
can display ``.clause`` to show what the discount applies to, and can display ``.clause`` to show what the discount applies to, and
``.quantity`` to display the number of times that discount can be ``.quantity`` to display the number of times that discount can be
applied. applied.
description (str): A description of the section. description (str): A description of the section.
form (forms.Form): A form to display. form (forms.Form): A form to display.
''' '''
pass pass
@ -568,7 +568,6 @@ def invoice_access(request, access_code):
user__attendee__access_code=access_code, user__attendee__access_code=access_code,
).order_by("-issue_time") ).order_by("-issue_time")
if not invoices: if not invoices:
raise Http404() raise Http404()
@ -630,7 +629,12 @@ def invoice(request, invoice_id, access_code=None):
return render(request, "registrasion/invoice.html", data) return render(request, "registrasion/invoice.html", data)
@login_required def _staff_only(user):
''' Returns true if the user is staff. '''
return user.is_staff
@user_passes_test(_staff_only)
def manual_payment(request, invoice_id): def manual_payment(request, invoice_id):
''' Allows staff to make manual payments or refunds on an invoice. ''' Allows staff to make manual payments or refunds on an invoice.
@ -650,16 +654,10 @@ def manual_payment(request, invoice_id):
# object. # object.
} }
Raises:
Http404: if the logged in user is not staff.
''' '''
FORM_PREFIX = "manual_payment" FORM_PREFIX = "manual_payment"
if not request.user.is_staff:
raise Http404()
current_invoice = InvoiceController.for_id_or_404(invoice_id) current_invoice = InvoiceController.for_id_or_404(invoice_id)
form = forms.ManualPaymentForm( form = forms.ManualPaymentForm(
@ -668,21 +666,21 @@ def manual_payment(request, invoice_id):
) )
if request.POST and form.is_valid(): if request.POST and form.is_valid():
form.instance.invoice = inv form.instance.invoice = current_invoice.invoice
form.instance.entered_by = request.user form.instance.entered_by = request.user
form.save() form.save()
current_invoice.update_status() current_invoice.update_status()
form = forms.ManualPaymentForm(prefix=FORM_PREFIX) form = forms.ManualPaymentForm(prefix=FORM_PREFIX)
data = { data = {
"invoice": inv, "invoice": current_invoice.invoice,
"form": form, "form": form,
} }
return render(request, "registrasion/manual_payment.html", data) return render(request, "registrasion/manual_payment.html", data)
@login_required @user_passes_test(_staff_only)
def refund(request, invoice_id): def refund(request, invoice_id):
''' Marks an invoice as refunded and requests a credit note for the ''' Marks an invoice as refunded and requests a credit note for the
full amount paid against the invoice. full amount paid against the invoice.
@ -696,14 +694,8 @@ def refund(request, invoice_id):
redirect: redirect:
Redirects to ``invoice``. Redirects to ``invoice``.
Raises:
Http404: if the logged in user is not staff.
''' '''
if not request.user.is_staff:
raise Http404()
current_invoice = InvoiceController.for_id_or_404(invoice_id) current_invoice = InvoiceController.for_id_or_404(invoice_id)
try: try:
@ -715,7 +707,7 @@ def refund(request, invoice_id):
return redirect("invoice", invoice_id) return redirect("invoice", invoice_id)
@login_required @user_passes_test(_staff_only)
def credit_note(request, note_id, access_code=None): def credit_note(request, note_id, access_code=None):
''' Displays a credit note. ''' Displays a credit note.
@ -741,19 +733,12 @@ def credit_note(request, note_id, access_code=None):
# refund of the credit note. # refund of the credit note.
} }
Raises:
Http404: If the logged in user is not staff.
''' '''
if not request.user.is_staff:
raise Http404()
current_note = CreditNoteController.for_id_or_404(note_id) current_note = CreditNoteController.for_id_or_404(note_id)
apply_form = forms.ApplyCreditNoteForm( apply_form = forms.ApplyCreditNoteForm(
note.invoice.user, current_note.credit_note.invoice.user,
request.POST or None, request.POST or None,
prefix="apply_note" prefix="apply_note"
) )
@ -775,7 +760,7 @@ def credit_note(request, note_id, access_code=None):
elif request.POST and refund_form.is_valid(): elif request.POST and refund_form.is_valid():
refund_form.instance.entered_by = request.user refund_form.instance.entered_by = request.user
refund_form.instance.parent = note refund_form.instance.parent = current_note.credit_note
refund_form.save() refund_form.save()
messages.success( messages.success(
request, request,

View file

@ -1,2 +1,2 @@
[flake8] [flake8]
exclude = registrasion/migrations/*, build/* exclude = registrasion/migrations/*, build/*, docs/*