diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 3fc440cae4..98dcab6287 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -858,6 +858,17 @@ class StockList(generics.ListCreateAPIView): print("After error:", str(updated_after)) pass + # Filter stock items which have a purchase price set + has_purchase_price = params.get('has_purchase_price', None) + + if has_purchase_price is not None: + has_purchase_price = str2bool(has_purchase_price) + + if has_purchase_price: + queryset = queryset.exclude(purchase_price=None) + else: + queryset = queryset.filter(purchase_price=None) + # Optionally, limit the maximum number of returned results max_results = params.get('max_results', None) diff --git a/InvenTree/templates/js/table_filters.js b/InvenTree/templates/js/table_filters.js index d02fa50d80..3dfb424edf 100644 --- a/InvenTree/templates/js/table_filters.js +++ b/InvenTree/templates/js/table_filters.js @@ -205,7 +205,12 @@ function getAvailableTableFilters(tableKey) { batch: { title: '{% trans "Batch" %}', description: '{% trans "Batch code" %}', - } + }, + has_purchase_price: { + type: 'bool', + title: '{% trans "Has purchase price" %}', + description: '{% trans "Show stock items which have a purchase price set" %}', + }, }; }