Changeset - 5debbb2ac82e
[Not reviewed]
Merge
0 10 0
Christopher Neugebauer - 8 years ago 2016-04-06 07:41:08
chrisjrn@gmail.com
Merge branch 'random_fixes'
10 files changed with 109 insertions and 65 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -59,2 +59,3 @@ class InvoiceController(object):
 
    @classmethod
 
    @transaction.atomic
 
    def _generate(cls, cart):
...
 
@@ -67,6 +68,8 @@ class InvoiceController(object):
 
        )
 
        invoice.save()
 

	
 
        # TODO: calculate line items.
 
        product_items = rego.ProductItem.objects.filter(cart=cart)
 

	
 
        if len(product_items) == 0:
 
            raise ValidationError("Your cart is empty.")
 

	
 
        product_items = product_items.order_by(
...
 
@@ -84,3 +87,2 @@ class InvoiceController(object):
 
            )
 
            line_item.save()
 
            invoice_value += line_item.quantity * line_item.price
...
 
@@ -94,7 +96,9 @@ class InvoiceController(object):
 
            )
 
            line_item.save()
 
            invoice_value += line_item.quantity * line_item.price
 

	
 
        # TODO: calculate line items from discounts
 
        invoice.value = invoice_value
 

	
 
        if invoice.value == 0:
 
            invoice.paid = True
 

	
 
        invoice.save()
registrasion/forms.py
Show inline comments
...
 
@@ -49,3 +49,6 @@ class _QuantityBoxProductsForm(_ProductsForm):
 
        for product in products:
 
            help_text = "$%d -- %s" % (product.price, product.description)
 
            if product.description:
 
                help_text = "$%d each -- %s" % (product.price, product.description)
 
            else:
 
                help_text = "$%d each" % product.price
 

	
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -37,4 +37,5 @@ def items_pending(context):
 
@register.assignment_tag(takes_context=True)
 
def items_purchased(context):
 
    ''' Returns all of the items that this user has purchased '''
 
def items_purchased(context, category=None):
 
    ''' Returns all of the items that this user has purchased, optionally
 
    from the given category. '''
 

	
...
 
@@ -45,2 +46,5 @@ def items_purchased(context):
 

	
 
    if category:
 
        all_items = all_items.filter(product__category=category)
 

	
 
    products = set(item.product for item in all_items)
registrasion/tests/cart_controller_helper.py
Show inline comments
...
 
@@ -26 +26,5 @@ class TestingCartController(CartController):
 
        self.set_quantity(product, old_quantity + quantity)
 

	
 
    def next_cart(self):
 
        self.cart.active = False
 
        self.cart.save()
registrasion/tests/test_cart.py
Show inline comments
...
 
@@ -76,8 +76,8 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
 
        current_cart = TestingCartController.for_user(cls.USER_1)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(cls.USER_2)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -144,4 +144,4 @@ class BasicCartTests(RegistrationCartTestCase):
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -216,4 +216,4 @@ class BasicCartTests(RegistrationCartTestCase):
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -274,4 +274,4 @@ class BasicCartTests(RegistrationCartTestCase):
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -300,4 +300,4 @@ class BasicCartTests(RegistrationCartTestCase):
 
        # The limits should extend across carts...
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -327,4 +327,4 @@ class BasicCartTests(RegistrationCartTestCase):
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
registrasion/tests/test_ceilings.py
Show inline comments
...
 
@@ -93,4 +93,4 @@ class CeilingsTestCases(RegistrationCartTestCase):
 
        # User 2 pays for their cart
 
        second_cart.cart.active = False
 
        second_cart.cart.save()
 

	
 
        second_cart.next_cart()
 

	
...
 
@@ -130,4 +130,4 @@ class CeilingsTestCases(RegistrationCartTestCase):
 
        # Paid cart outside the reservation window
 
        second_cart.cart.active = False
 
        second_cart.cart.save()
 

	
 
        second_cart.next_cart()
 
        self.add_timedelta(self.RESERVATION + datetime.timedelta(seconds=1))
...
 
@@ -142,4 +142,4 @@ class CeilingsTestCases(RegistrationCartTestCase):
 

	
 
        first_cart.cart.active = False
 
        first_cart.cart.save()
 

	
 
        first_cart.next_cart()
 

	
...
 
@@ -150,3 +150,3 @@ class CeilingsTestCases(RegistrationCartTestCase):
 
        first_cart.cart.released = True
 
        first_cart.cart.save()
 
        first_cart.next_cart()
 

	
...
 
@@ -178,4 +178,4 @@ class CeilingsTestCases(RegistrationCartTestCase):
 

	
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
registrasion/tests/test_discount.py
Show inline comments
...
 
@@ -170,4 +170,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        cart.add_to_cart(self.PROD_1, 1)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
...
 
@@ -179,4 +179,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.assertEqual(1, len(cart.cart.discountitem_set.all()))
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
...
 
@@ -199,4 +199,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        cart.add_to_cart(self.PROD_2, 2)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
...
 
@@ -348,5 +348,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.assertEqual(2, discounts[0].quantity)
 
        inv = InvoiceController.for_cart(cart.cart)
 
        inv.pay("Dummy reference", inv.invoice.value)
 
        self.assertTrue(inv.invoice.paid)
 

	
 
        cart.next_cart()
 

	
...
 
@@ -360,5 +359,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.assertEqual(1, discounts[0].quantity)
 
        inv = InvoiceController.for_cart(cart.cart)
 
        inv.pay("Dummy reference", inv.invoice.value)
 
        self.assertTrue(inv.invoice.paid)
 

	
 
        cart.next_cart()
 

	
...
 
@@ -392,3 +390,3 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        cart.cart.active = False  # Keep discount enabled
 
        cart.cart.save()
 
        cart.next_cart()
 

	
...
 
@@ -396,4 +394,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        cart.add_to_cart(self.PROD_2, 2)  # The discount will be exhausted
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
...
 
@@ -407,3 +405,3 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        cart.cart.released = True
 
        cart.cart.save()
 
        cart.next_cart()
 

	
registrasion/tests/test_enabling_condition.py
Show inline comments
...
 
@@ -70,4 +70,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
        current_cart.add_to_cart(self.PROD_2, 1)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -105,4 +105,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
        current_cart.add_to_cart(self.PROD_3, 1)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -243,4 +243,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
...
 
@@ -251,3 +251,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
        cart.cart.released = True
 
        cart.cart.save()
 
        cart.next_cart()
 

	
...
 
@@ -262,4 +262,4 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
...
 
@@ -270,3 +270,3 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
        cart.cart.released = True
 
        cart.cart.save()
 
        cart.next_cart()
 

	
registrasion/tests/test_invoice.py
Show inline comments
...
 
@@ -85,3 +85,2 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        )
 
        voucher.save()
 
        discount = rego.VoucherDiscount.objects.create(
...
 
@@ -90,3 +89,2 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        )
 
        discount.save()
 
        rego.DiscountForProduct.objects.create(
...
 
@@ -96,3 +94,3 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
            quantity=1
 
        ).save()
 
        )
 

	
...
 
@@ -113,2 +111,28 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_zero_value_invoice_is_automatically_paid(self):
 
        voucher = rego.Voucher.objects.create(
 
            recipient="Voucher recipient",
 
            code="VOUCHER",
 
            limit=1
 
        )
 
        discount = rego.VoucherDiscount.objects.create(
 
            description="VOUCHER RECIPIENT",
 
            voucher=voucher,
 
        )
 
        rego.DiscountForProduct.objects.create(
 
            discount=discount,
 
            product=self.PROD_1,
 
            percentage=Decimal(100),
 
            quantity=1
 
        )
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.apply_voucher(voucher.code)
 

	
 
        # Should be able to create an invoice after the product is added
 
        current_cart.add_to_cart(self.PROD_1, 1)
 
        invoice_1 = InvoiceController.for_cart(current_cart.cart)
 

	
 
        self.assertTrue(invoice_1.invoice.paid)
 

	
 
    def test_invoice_voids_self_if_cart_is_invalid(self):
...
 
@@ -171 +195,6 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
            invoice_1.void()
 

	
 
    def test_cannot_generate_blank_invoice(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        with self.assertRaises(ValidationError):
 
            invoice_1 = InvoiceController.for_cart(current_cart.cart)
registrasion/tests/test_voucher.py
Show inline comments
...
 
@@ -36,4 +36,4 @@ class VoucherTestCases(RegistrationCartTestCase):
 
        cart_2.apply_voucher(voucher.code)
 
        cart_2.cart.active = False
 
        cart_2.cart.save()
 

	
 
        cart_2.next_cart()
 

	
...
 
@@ -127,4 +127,4 @@ class VoucherTestCases(RegistrationCartTestCase):
 

	
 
        inv = InvoiceController.for_cart(current_cart.cart)
 
        inv.pay("Hello!", inv.invoice.value)
 

	
 
        current_cart.next_cart()
 

	
...
 
@@ -141,5 +141,7 @@ class VoucherTestCases(RegistrationCartTestCase):
 
        current_cart.apply_voucher(voucher.code)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        inv = InvoiceController.for_cart(current_cart.cart)
 
        inv.pay("Hello!", inv.invoice.value)
 
        if not inv.invoice.paid:
 
            inv.pay("Hello!", inv.invoice.value)
 

	
0 comments (0 inline, 0 general)