From 232dc9e452227a5d6806cbc96d8a3e7e0fc5bf04 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Thu, 13 Oct 2016 09:19:18 -0700 Subject: [PATCH] Invoices are tested for cart validity before display. Fixes #99. --- registrasion/controllers/invoice.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/registrasion/controllers/invoice.py b/registrasion/controllers/invoice.py index 84af2a87..3b675e17 100644 --- a/registrasion/controllers/invoice.py +++ b/registrasion/controllers/invoice.py @@ -357,8 +357,18 @@ class InvoiceController(ForId, object): 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()