2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Merge pull request #1757 from matmair/stock-next-prev

Stock previous / next serial
This commit is contained in:
Oliver
2021-07-08 11:41:01 +10:00
committed by GitHub
2 changed files with 36 additions and 1 deletions

View File

@ -86,6 +86,29 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
queryset = StockItem.objects.all()
model = StockItem
def get_context_data(self, **kwargs):
""" add previous and next item """
data = super().get_context_data(**kwargs)
if self.object.serialized:
serial_elem = {a.serial: a for a in self.object.part.stock_items.all() if a.serialized}
serials = [int(a) for a in serial_elem.keys()]
current = int(self.object.serial)
# previous
for nbr in range(current - 1, -1, -1):
if nbr in serials:
data['previous'] = serial_elem.get(str(nbr), None)
break
# next
for nbr in range(current + 1, max(serials) + 1):
if nbr in serials:
data['next'] = serial_elem.get(str(nbr), None)
break
return data
class StockItemNotes(InvenTreeRoleMixin, UpdateView):
""" View for editing the 'notes' field of a StockItem object """