@@ -74,52 +74,76 @@ class InvoiceTestCase(RegistrationCartTestCase):
self.assertFalse(invoice.invoice.cart.active)
# Asking for a cart should generate a new one
new_cart = TestingCartController.for_user(self.USER_1)
self.assertNotEqual(current_cart.cart, new_cart.cart)
def test_invoice_includes_discounts(self):
voucher = rego.Voucher.objects.create(
recipient="Voucher recipient",
code="VOUCHER",
limit=1
)
voucher.save()
discount = rego.VoucherDiscount.objects.create(
description="VOUCHER RECIPIENT",
voucher=voucher,
discount.save()
rego.DiscountForProduct.objects.create(
discount=discount,
product=self.PROD_1,
percentage=Decimal(50),
quantity=1
).save()
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)
# That invoice should have two line items
line_items = rego.LineItem.objects.filter(invoice=invoice_1.invoice)
self.assertEqual(2, len(line_items))
# That invoice should have a value equal to 50% of the cost of PROD_1
self.assertEqual(
self.PROD_1.price * Decimal("0.5"),
invoice_1.invoice.value)
def test_zero_value_invoice_is_automatically_paid(self):
percentage=Decimal(100),
self.assertTrue(invoice_1.invoice.paid)
def test_invoice_voids_self_if_cart_is_invalid(self):
self.assertFalse(invoice_1.invoice.void)
# Adding item to cart should produce a new invoice
current_cart.add_to_cart(self.PROD_2, 1)
invoice_2 = InvoiceController.for_cart(current_cart.cart)
@@ -160,12 +184,17 @@ class InvoiceTestCase(RegistrationCartTestCase):
def test_cannot_void_paid_invoice(self):
invoice_1.pay("Reference", invoice_1.invoice.value)
with self.assertRaises(ValidationError):
invoice_1.void()
def test_cannot_generate_blank_invoice(self):