Changeset - 84c40a1e1f28
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-09-03 05:08:25
chrisjrn@gmail.com
Refactors ItemController, add items_released
1 file changed with 29 insertions and 13 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/item.py
Show inline comments
...
 
@@ -32,3 +32,3 @@ class ItemController(object):
 

	
 
    def items_purchased(self, category=None):
 
    def _items(self, cart_status, category=None):
 
        ''' Aggregates the items that this user has purchased.
...
 
@@ -47,3 +47,3 @@ class ItemController(object):
 
            Q(productitem__cart__user=self.user) &
 
            Q(productitem__cart__status=commerce.Cart.STATUS_PAID)
 
            Q(productitem__cart__status=cart_status)
 
        )
...
 
@@ -74,2 +74,16 @@ class ItemController(object):
 

	
 
    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):
...
 
@@ -84,12 +98,14 @@ class ItemController(object):
 

	
 
        all_items = commerce.ProductItem.objects.filter(
 
            cart__user=self.user,
 
            cart__status=commerce.Cart.STATUS_ACTIVE,
 
        ).select_related(
 
            "product",
 
            "product__category",
 
        ).order_by(
 
            "product__category__order",
 
            "product__order",
 
        )
 
        return all_items
 
        return self._items(commerce.Cart.STATUS_ACTIVE)
 

	
 
    def items_released(self):
 
        ''' Gets all of the items that the user previously paid for, but has
 
        since refunded.
 

	
 
        Returns:
 
            [ProductAndQuantity, ...]: A list of product-quantity pairs for the
 
                items that the user has not yet paid for.
 

	
 
        '''
 

	
 
        return self._items(commerce.Cart.STATUS_RELEASED)
0 comments (0 inline, 0 general)