diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index b674c5c7fc..2eb7695498 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -247,7 +247,19 @@ {% trans "Serial Number" %} - {{ item.serial }} + + {% if previous %} + + {{ previous.serial }} ‹ + + {% endif %} + {{ item.serial }} + {% if next %} + + › {{ next.serial }} + + {% endif %} + {% else %} diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 06f9b05b20..c74b0bb2fc 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -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 """