Improve filtering for stock items

This commit is contained in:
Oliver Walters 2019-06-02 09:14:45 +10:00
parent 011f5a5efd
commit e278bdbb90
2 changed files with 9 additions and 9 deletions

View File

@ -6,10 +6,9 @@
{% csrf_token %}
{% load crispy_forms_tags %}
<b>Stock Items</b>
<table class='table table-condensed table-striped' id='stock-table'>
<tr>
<th>Item</th>
<th>Stock Item</th>
<th>Location</th>
<th>{{ stock_action }}</th>
<th></th>

View File

@ -135,15 +135,14 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
stock_items = []
def get_items(self, item_list):
""" Return list of stock items. """
""" Return list of stock items initally requested using GET """
items = []
# Start with all 'in stock' items
items = StockItem.objects.filter(customer=None, belongs_to=None)
for pk in item_list:
try:
items.append(StockItem.objects.get(pk=pk))
except StockItem.DoesNotExist:
pass
# Client provides a list of individual stock items
if 'stock[]' in self.request.GET:
items = items.filter(id__in=self.request.GET.getlist('stock[]'))
return items
@ -166,6 +165,8 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
def get(self, request, *args, **kwargs):
self.request = request
# Save list of items!
self.stock_items = self.get_items(request.GET.getlist('stock[]'))