Makes ProductCondition work if you have both valid and cancelled instances of a product. Fixes #68
This commit is contained in:
		
							parent
							
								
									8e1f799513
								
							
						
					
					
						commit
						43649002cb
					
				
					 2 changed files with 16 additions and 2 deletions
				
			
		|  | @ -172,11 +172,20 @@ class ProductConditionController(IsMetByFilter, ConditionController): | |||
| 
 | ||||
|         in_user_carts = Q(enabling_products__productitem__cart__user=user) | ||||
|         released = commerce.Cart.STATUS_RELEASED | ||||
|         paid = commerce.Cart.STATUS_PAID | ||||
|         active = commerce.Cart.STATUS_ACTIVE | ||||
|         in_released_carts = Q( | ||||
|             enabling_products__productitem__cart__status=released | ||||
|         ) | ||||
|         not_in_paid_or_active_carts = ~( | ||||
|             Q(enabling_products__productitem__cart__status=paid) | | ||||
|             Q(enabling_products__productitem__cart__status=active) | ||||
|         ) | ||||
| 
 | ||||
|         queryset = queryset.filter(in_user_carts) | ||||
|         queryset = queryset.exclude(in_released_carts) | ||||
|         queryset = queryset.exclude( | ||||
|             in_released_carts & not_in_paid_or_active_carts | ||||
|         ) | ||||
| 
 | ||||
|         return queryset | ||||
| 
 | ||||
|  |  | |||
|  | @ -352,7 +352,7 @@ class FlagTestCases(RegistrationCartTestCase): | |||
|         items = commerce.ProductItem.objects.filter(cart=cart.cart) | ||||
|         self.assertTrue([i for i in items if i.product == self.PROD_1]) | ||||
| 
 | ||||
|     def test_oops(self): | ||||
|     def test_product_stays_enabled_even_if_some_are_cancelled(self): | ||||
|         ''' Flags should be enabled, even if *some* enabling products are cnx. | ||||
|         Tests issue #68. | ||||
|         ''' | ||||
|  | @ -377,3 +377,8 @@ class FlagTestCases(RegistrationCartTestCase): | |||
|         # Even though cart1 has been cancelled, we have the item in cart2. | ||||
|         # So we should be able to add PROD_1, which depends on PROD_2 | ||||
|         cart2.add_to_cart(self.PROD_1, 1) | ||||
| 
 | ||||
|         cart2.set_quantity(self.PROD_2, 0) | ||||
| 
 | ||||
|         with self.assertRaises(ValidationError): | ||||
|             cart2.add_to_cart(self.PROD_1, 1) | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer