Changeset - 6a5e4ff92db8
[Not reviewed]
Merge
0 4 0
Christopher Neugebauer - 8 years ago 2016-10-13 16:37:26
chrisjrn@gmail.com
Merge branch 'chrisjrn/20161013'
4 files changed with 54 insertions and 3 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -354,14 +354,24 @@ class InvoiceController(ForId, object):
 
        if not cart:
 
            return True
 

	
 
        return cart.revision == self.invoice.cart_revision
 

	
 
    def update_validity(self):
 
        ''' Voids this invoice if the cart it is attached to has updated. '''
 
        if not self._invoice_matches_cart():
 
        ''' Voids this invoice if the attached cart is no longer valid because
 
        the cart revision has changed, or the reservations have expired. '''
 

	
 
        is_valid = self._invoice_matches_cart()
 
        cart = self.invoice.cart
 
        if self.invoice.is_unpaid and is_valid and cart:
 
            try:
 
                CartController(cart).validate_cart()
 
            except ValidationError:
 
                is_valid = False
 

	
 
        if not is_valid:
 
            if self.invoice.total_payments() > 0:
 
                # Free up the payments made to this invoice
 
                self.refund()
 
            else:
 
                self.void()
 

	
registrasion/reporting/views.py
Show inline comments
...
 
@@ -379,12 +379,27 @@ def credit_notes(request, form):
 
        notes,
 
        headings=["id", "Owner", "Status", "Value"],
 
        link_view=views.credit_note,
 
    )
 

	
 

	
 
@report_view("Invoices")
 
def invoices(request,form):
 
    ''' Shows all of the invoices in the system. '''
 

	
 
    invoices = commerce.Invoice.objects.all().order_by("status")
 

	
 
    return QuerysetReport(
 
        "Invoices",
 
        ["id", "recipient", "value", "get_status_display"],
 
        invoices,
 
        headings=["id", "Recipient", "Value", "Status"],
 
        link_view=views.invoice,
 
    )
 

	
 

	
 
class AttendeeListReport(ListReport):
 

	
 
    def get_link(self, argument):
 
        return reverse(self._link_view) + "?user=%d" % int(argument)
 

	
 

	
registrasion/tests/test_invoice.py
Show inline comments
...
 
@@ -165,13 +165,13 @@ class InvoiceTestCase(TestHelperMixin, RegistrationCartTestCase):
 
        # Should be able to create an invoice after the product is added
 
        current_cart.add_to_cart(self.PROD_1, 1)
 
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
 

	
 
        self.assertTrue(invoice_1.invoice.is_paid)
 

	
 
    def test_invoice_voids_self_if_cart_is_invalid(self):
 
    def test_invoice_voids_self_if_cart_changes(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

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

	
...
 
@@ -187,12 +187,37 @@ class InvoiceTestCase(TestHelperMixin, RegistrationCartTestCase):
 
        self.assertTrue(invoice_1_new.invoice.is_void)
 

	
 
        # Viewing invoice_2's invoice should *not* show it as void
 
        invoice_2_new = TestingInvoiceController(invoice_2.invoice)
 
        self.assertFalse(invoice_2_new.invoice.is_void)
 

	
 
    def test_invoice_voids_self_if_cart_becomes_invalid(self):
 
        ''' Invoices should be void if cart becomes invalid over time '''
 

	
 
        self.make_ceiling("Limit ceiling", limit=1)
 
        self.set_time(datetime.datetime(
 
            year=2015, month=1, day=1, hour=0, minute=0, tzinfo=UTC,
 
        ))
 

	
 
        cart1 = TestingCartController.for_user(self.USER_1)
 
        cart2 = TestingCartController.for_user(self.USER_2)
 

	
 
        # Create a valid invoice for USER_1
 
        cart1.add_to_cart(self.PROD_1, 1)
 
        inv1 = TestingInvoiceController.for_cart(cart1.cart)
 

	
 
        # Expire the reservations, and have USER_2 take up PROD_1's ceiling
 
        # generate an invoice
 
        self.add_timedelta(self.RESERVATION * 2)
 
        cart2.add_to_cart(self.PROD_2, 1)
 
        inv2 = TestingInvoiceController.for_cart(cart2.cart)
 

	
 
        # Re-get inv1's invoice; it should void itself on loading.
 
        inv1 = TestingInvoiceController(inv1.invoice)
 
        self.assertTrue(inv1.invoice.is_void)
 

	
 
    def test_voiding_invoice_creates_new_invoice(self):
 
        invoice_1 = self._invoice_containing_prod_1(1)
 

	
 
        self.assertFalse(invoice_1.invoice.is_void)
 
        invoice_1.void()
 

	
registrasion/urls.py
Show inline comments
...
 
@@ -46,12 +46,13 @@ reports = [
 
    url(r"^$", rv.reports_list, name="reports_list"),
 
    url(r"^attendee/?$", rv.attendee, name="attendee"),
 
    url(r"^attendee_data/?$", rv.attendee_data, name="attendee_data"),
 
    url(r"^attendee/([0-9]*)$", rv.attendee, name="attendee"),
 
    url(r"^credit_notes/?$", rv.credit_notes, name="credit_notes"),
 
    url(r"^discount_status/?$", rv.discount_status, name="discount_status"),
 
    url(r"^invoices/?$", rv.invoices, name="invoices"),
 
    url(
 
        r"^paid_invoices_by_date/?$",
 
        rv.paid_invoices_by_date,
 
        name="paid_invoices_by_date"
 
    ),
 
    url(r"^product_status/?$", rv.product_status, name="product_status"),
0 comments (0 inline, 0 general)