Skip to content

Commit

Permalink
Merge pull request #1744 from matmair/stock-table-has-price
Browse files Browse the repository at this point in the history
Stock table filter: has purchase price
  • Loading branch information
SchrodingersGat committed Jul 3, 2021
2 parents 1d5429f + f051714 commit d8f5cc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions InvenTree/stock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,17 @@ def filter_queryset(self, queryset):
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)

Expand Down
7 changes: 6 additions & 1 deletion InvenTree/templates/js/table_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}',
},
};
}

Expand Down

0 comments on commit d8f5cc7

Please sign in to comment.