Modify limits report to include category inclusions as well
* A TimeOrStockLimit limit can apply a limit to a whole category, or to specific products * This report was only counting the products directly listed * Take advantage of the new all_products property to include the products indirectly listed as well as those directly listed
This commit is contained in:
		
							parent
							
								
									6a9652dfd2
								
							
						
					
					
						commit
						1fd8364456
					
				
					 1 changed files with 5 additions and 9 deletions
				
			
		|  | @ -248,7 +248,7 @@ def group_by_cart_status(queryset, order, values): | |||
| def limits(request, form): | ||||
|     ''' Shows the summary of sales against stock limits. ''' | ||||
| 
 | ||||
|     line_items = commerce.ProductItem.objects.filter( | ||||
|     product_items = commerce.ProductItem.objects.filter( | ||||
|         cart__status=commerce.Invoice.STATUS_PAID, | ||||
|     ).values( | ||||
|         "product", "product__name", | ||||
|  | @ -256,10 +256,6 @@ def limits(request, form): | |||
|         total_quantity=Sum("quantity") | ||||
|     ) | ||||
| 
 | ||||
|     quantities = collections.defaultdict(int) | ||||
|     for line_item in line_items.all(): | ||||
|         quantities[line_item['product__name']] += line_item['total_quantity'] | ||||
| 
 | ||||
|     limits = conditions.TimeOrStockLimitFlag.objects.all().order_by("-limit") | ||||
| 
 | ||||
|     headings = ["Product", "Quantity"] | ||||
|  | @ -268,10 +264,10 @@ def limits(request, form): | |||
|     for limit in limits: | ||||
|         data = [] | ||||
|         total = 0 | ||||
|         for product in limit.products.all(): | ||||
|             if product.name in quantities: | ||||
|                 total += quantities[product.name] | ||||
|                 data.append([product.name, quantities[product.name]]) | ||||
|         limit_items = product_items.filter(product__in=limit.all_products) | ||||
|         for product in limit_items: | ||||
|             data.append([product['product__name'], product['total_quantity']]) | ||||
|             total += product['total_quantity'] | ||||
|         if limit.limit: | ||||
|             data.append(['(TOTAL)', '%s/%s' % (total, limit.limit)]) | ||||
|         else: | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 James Polley
						James Polley