Refactors ItemController, add items_released
This commit is contained in:
		
							parent
							
								
									83b8b62d74
								
							
						
					
					
						commit
						84c40a1e1f
					
				
					 1 changed files with 29 additions and 13 deletions
				
			
		|  | @ -30,7 +30,7 @@ class ItemController(object): | ||||||
|     def __init__(self, user): |     def __init__(self, user): | ||||||
|         self.user = user |         self.user = user | ||||||
| 
 | 
 | ||||||
|     def items_purchased(self, category=None): |     def _items(self, cart_status, category=None): | ||||||
|         ''' Aggregates the items that this user has purchased. |         ''' Aggregates the items that this user has purchased. | ||||||
| 
 | 
 | ||||||
|         Arguments: |         Arguments: | ||||||
|  | @ -45,7 +45,7 @@ class ItemController(object): | ||||||
| 
 | 
 | ||||||
|         in_cart = ( |         in_cart = ( | ||||||
|             Q(productitem__cart__user=self.user) & |             Q(productitem__cart__user=self.user) & | ||||||
|             Q(productitem__cart__status=commerce.Cart.STATUS_PAID) |             Q(productitem__cart__status=cart_status) | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         quantities_in_cart = When( |         quantities_in_cart = When( | ||||||
|  | @ -72,6 +72,20 @@ class ItemController(object): | ||||||
|             out.append(ProductAndQuantity(prod, prod.quantity)) |             out.append(ProductAndQuantity(prod, prod.quantity)) | ||||||
|         return out |         return out | ||||||
| 
 | 
 | ||||||
|  |     def items_purchased(self, category=None): | ||||||
|  |         ''' Aggregates the items that this user has purchased. | ||||||
|  | 
 | ||||||
|  |         Arguments: | ||||||
|  |             category (Optional[models.inventory.Category]): the category | ||||||
|  |                 of items to restrict to. | ||||||
|  | 
 | ||||||
|  |         Returns: | ||||||
|  |             [ProductAndQuantity, ...]: A list of product-quantity pairs, | ||||||
|  |                 aggregating like products from across multiple invoices. | ||||||
|  | 
 | ||||||
|  |         ''' | ||||||
|  |         return self._items(commerce.Cart.STATUS_PAID) | ||||||
|  | 
 | ||||||
|     def items_pending(self): |     def items_pending(self): | ||||||
|         ''' Gets all of the items that the user has reserved, but has not yet |         ''' Gets all of the items that the user has reserved, but has not yet | ||||||
|         paid for. |         paid for. | ||||||
|  | @ -82,14 +96,16 @@ class ItemController(object): | ||||||
| 
 | 
 | ||||||
|         ''' |         ''' | ||||||
| 
 | 
 | ||||||
|         all_items = commerce.ProductItem.objects.filter( |         return self._items(commerce.Cart.STATUS_ACTIVE) | ||||||
|             cart__user=self.user, | 
 | ||||||
|             cart__status=commerce.Cart.STATUS_ACTIVE, |     def items_released(self): | ||||||
|         ).select_related( |         ''' Gets all of the items that the user previously paid for, but has | ||||||
|             "product", |         since refunded. | ||||||
|             "product__category", | 
 | ||||||
|         ).order_by( |         Returns: | ||||||
|             "product__category__order", |             [ProductAndQuantity, ...]: A list of product-quantity pairs for the | ||||||
|             "product__order", |                 items that the user has not yet paid for. | ||||||
|         ) | 
 | ||||||
|         return all_items |         ''' | ||||||
|  | 
 | ||||||
|  |         return self._items(commerce.Cart.STATUS_RELEASED) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer