mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Add ability to filter by 'expired' status in API
This commit is contained in:
		| @@ -525,6 +525,17 @@ class StockList(generics.ListCreateAPIView): | |||||||
|                 # Exclude items which are instaled in another item |                 # Exclude items which are instaled in another item | ||||||
|                 queryset = queryset.filter(belongs_to=None) |                 queryset = queryset.filter(belongs_to=None) | ||||||
|  |  | ||||||
|  |         # Filter by 'expired' status | ||||||
|  |         expired = params.get('expired', None) | ||||||
|  |  | ||||||
|  |         if expired is not None: | ||||||
|  |             expired = str2bool(expired) | ||||||
|  |  | ||||||
|  |             if expired: | ||||||
|  |                 queryset = queryset.filter(StockItem.EXPIRED_FILTER) | ||||||
|  |             else: | ||||||
|  |                 queryset = queryset.exclude(StockItem.EXPIRED_FILTER) | ||||||
|  |  | ||||||
|         # Filter by customer |         # Filter by customer | ||||||
|         customer = params.get('customer', None) |         customer = params.get('customer', None) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -150,6 +150,9 @@ class StockItem(MPTTModel): | |||||||
|         status__in=StockStatus.AVAILABLE_CODES |         status__in=StockStatus.AVAILABLE_CODES | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     # A query filter which can be used to filter StockItem objects which have expired | ||||||
|  |     EXPIRED_FILTER = IN_STOCK_FILTER & ~Q(expiry_date=None) & Q(expiry_date__lt=datetime.now().date()) | ||||||
|  |  | ||||||
|     def save(self, *args, **kwargs): |     def save(self, *args, **kwargs): | ||||||
|         """ |         """ | ||||||
|         Save this StockItem to the database. Performs a number of checks: |         Save this StockItem to the database. Performs a number of checks: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user