Merge branch 'chrisjrn/20161013'
This commit is contained in:
		
						commit
						4e3f4aa9ad
					
				
					 4 changed files with 58 additions and 8 deletions
				
			
		|  | @ -310,7 +310,12 @@ class SpeakerConditionController(IsMetByFilter, ConditionController): | ||||||
|     @classmethod |     @classmethod | ||||||
|     def pre_filter(self, queryset, user): |     def pre_filter(self, queryset, user): | ||||||
|         ''' Returns all of the items from queryset which are enabled by a user |         ''' Returns all of the items from queryset which are enabled by a user | ||||||
|         being a presenter or copresenter of a proposal. ''' |         being a presenter or copresenter of a non-cancelled proposal. ''' | ||||||
|  | 
 | ||||||
|  |         # Filter out cancelled proposals | ||||||
|  |         queryset = queryset.filter( | ||||||
|  |             proposal_kind__proposalbase__presentation__cancelled=False | ||||||
|  |         ) | ||||||
| 
 | 
 | ||||||
|         u = user |         u = user | ||||||
|         # User is a presenter |         # User is a presenter | ||||||
|  |  | ||||||
|  | @ -331,10 +331,7 @@ class InvoiceController(ForId, object): | ||||||
|     def _mark_refunded(self): |     def _mark_refunded(self): | ||||||
|         ''' Marks the invoice as refunded, and updates the attached cart if |         ''' Marks the invoice as refunded, and updates the attached cart if | ||||||
|         necessary. ''' |         necessary. ''' | ||||||
|         cart = self.invoice.cart |         self._release_cart() | ||||||
|         if cart: |  | ||||||
|             cart.status = commerce.Cart.STATUS_RELEASED |  | ||||||
|             cart.save() |  | ||||||
|         self.invoice.status = commerce.Invoice.STATUS_REFUNDED |         self.invoice.status = commerce.Invoice.STATUS_REFUNDED | ||||||
|         self.invoice.save() |         self.invoice.save() | ||||||
| 
 | 
 | ||||||
|  | @ -356,6 +353,12 @@ class InvoiceController(ForId, object): | ||||||
| 
 | 
 | ||||||
|         return cart.revision == self.invoice.cart_revision |         return cart.revision == self.invoice.cart_revision | ||||||
| 
 | 
 | ||||||
|  |     def _release_cart(self): | ||||||
|  |         cart = self.invoice.cart | ||||||
|  |         if cart: | ||||||
|  |             cart.status = commerce.Cart.STATUS_RELEASED | ||||||
|  |             cart.save() | ||||||
|  | 
 | ||||||
|     def update_validity(self): |     def update_validity(self): | ||||||
|         ''' Voids this invoice if the attached cart is no longer valid because |         ''' Voids this invoice if the attached cart is no longer valid because | ||||||
|         the cart revision has changed, or the reservations have expired. ''' |         the cart revision has changed, or the reservations have expired. ''' | ||||||
|  | @ -381,6 +384,9 @@ class InvoiceController(ForId, object): | ||||||
|             raise ValidationError("Invoices with payments must be refunded.") |             raise ValidationError("Invoices with payments must be refunded.") | ||||||
|         elif self.invoice.is_refunded: |         elif self.invoice.is_refunded: | ||||||
|             raise ValidationError("Refunded invoices may not be voided.") |             raise ValidationError("Refunded invoices may not be voided.") | ||||||
|  |         if self.invoice.is_paid: | ||||||
|  |             self._release_cart() | ||||||
|  | 
 | ||||||
|         self._mark_void() |         self._mark_void() | ||||||
| 
 | 
 | ||||||
|     @transaction.atomic |     @transaction.atomic | ||||||
|  |  | ||||||
|  | @ -142,7 +142,7 @@ class InvoiceTestCase(TestHelperMixin, RegistrationCartTestCase): | ||||||
|             self.PROD_1.price * Decimal("0.5"), |             self.PROD_1.price * Decimal("0.5"), | ||||||
|             invoice_1.invoice.value) |             invoice_1.invoice.value) | ||||||
| 
 | 
 | ||||||
|     def test_zero_value_invoice_is_automatically_paid(self): |     def _make_zero_value_invoice(self): | ||||||
|         voucher = inventory.Voucher.objects.create( |         voucher = inventory.Voucher.objects.create( | ||||||
|             recipient="Voucher recipient", |             recipient="Voucher recipient", | ||||||
|             code="VOUCHER", |             code="VOUCHER", | ||||||
|  | @ -164,10 +164,21 @@ class InvoiceTestCase(TestHelperMixin, RegistrationCartTestCase): | ||||||
| 
 | 
 | ||||||
|         # Should be able to create an invoice after the product is added |         # Should be able to create an invoice after the product is added | ||||||
|         current_cart.add_to_cart(self.PROD_1, 1) |         current_cart.add_to_cart(self.PROD_1, 1) | ||||||
|         invoice_1 = TestingInvoiceController.for_cart(current_cart.cart) |         return TestingInvoiceController.for_cart(current_cart.cart) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |     def test_zero_value_invoice_is_automatically_paid(self): | ||||||
|  |         invoice_1 = self._make_zero_value_invoice() | ||||||
|         self.assertTrue(invoice_1.invoice.is_paid) |         self.assertTrue(invoice_1.invoice.is_paid) | ||||||
| 
 | 
 | ||||||
|  |     def test_refunding_zero_value_invoice_releases_cart(self): | ||||||
|  |         invoice_1 = self._make_zero_value_invoice() | ||||||
|  |         cart = invoice_1.invoice.cart | ||||||
|  |         invoice_1.refund() | ||||||
|  | 
 | ||||||
|  |         cart.refresh_from_db() | ||||||
|  |         self.assertEquals(commerce.Cart.STATUS_RELEASED, cart.status) | ||||||
|  | 
 | ||||||
|     def test_invoice_voids_self_if_cart_changes(self): |     def test_invoice_voids_self_if_cart_changes(self): | ||||||
|         current_cart = TestingCartController.for_user(self.USER_1) |         current_cart = TestingCartController.for_user(self.USER_1) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,8 +11,10 @@ from registrasion.controllers.product import ProductController | ||||||
| 
 | 
 | ||||||
| from symposion.conference import models as conference_models | from symposion.conference import models as conference_models | ||||||
| from symposion.proposals import models as proposal_models | from symposion.proposals import models as proposal_models | ||||||
| from symposion.speakers import models as speaker_models |  | ||||||
| from symposion.reviews.models import promote_proposal | from symposion.reviews.models import promote_proposal | ||||||
|  | from symposion.schedule import models as schedule_models | ||||||
|  | from symposion.speakers import models as speaker_models | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| from test_cart import RegistrationCartTestCase | from test_cart import RegistrationCartTestCase | ||||||
| 
 | 
 | ||||||
|  | @ -207,3 +209,29 @@ class SpeakerTestCase(RegistrationCartTestCase): | ||||||
|             products=[self.PROD_1], |             products=[self.PROD_1], | ||||||
|         ) |         ) | ||||||
|         self.assertNotIn(self.PROD_1, available_1) |         self.assertNotIn(self.PROD_1, available_1) | ||||||
|  | 
 | ||||||
|  |     def test_proposal_cancelled_disables_condition(self): | ||||||
|  |         self._create_proposals() | ||||||
|  |         self._create_flag_for_primary_speaker() | ||||||
|  | 
 | ||||||
|  |         # USER_1 cannot see PROD_1 until proposal is promoted. | ||||||
|  |         available = ProductController.available_products( | ||||||
|  |             self.USER_1, | ||||||
|  |             products=[self.PROD_1], | ||||||
|  |         ) | ||||||
|  |         self.assertNotIn(self.PROD_1, available) | ||||||
|  | 
 | ||||||
|  |         # promote proposal_1 so that USER_1 becomes a speaker | ||||||
|  |         promote_proposal(self.PROPOSAL_1) | ||||||
|  |         presentation = schedule_models.Presentation.objects.get( | ||||||
|  |             proposal_base=self.PROPOSAL_1 | ||||||
|  |         ) | ||||||
|  |         presentation.cancelled = True | ||||||
|  |         presentation.save() | ||||||
|  | 
 | ||||||
|  |         # USER_1 can *NOT* see PROD_1 because proposal_1 has been cancelled | ||||||
|  |         available_after_cancelled = ProductController.available_products( | ||||||
|  |             self.USER_1, | ||||||
|  |             products=[self.PROD_1], | ||||||
|  |         ) | ||||||
|  |         self.assertNotIn(self.PROD_1, available_after_cancelled) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer