prev and next serial link in stock items

This commit is contained in:
Matthias 2021-07-05 00:47:45 +02:00
parent 369acb494b
commit 1786c029b4
2 changed files with 33 additions and 1 deletions

View File

@ -247,7 +247,16 @@
<tr>
<td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Serial Number" %}</td>
<td>{{ item.serial }}</td>
<td>
{% resolve request.path as url_path %}
{% if previous %}
<a class="btn btn-default" aria-label="{% trans 'previous page' %}" href="{% url url_path.url_name previous.id %}">{{ previous.serial }} </a>
{% endif %}
<span class="btn" href="">{{ item.serial }}</span>
{% if next %}
<a class="btn btn-default" aria-label="{% trans 'next page' %}" href="{% url url_path.url_name next.id %}"> {{ next.serial }}</a>
{% endif %}
</td>
</tr>
{% else %}
<tr>

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, 0, -1):
if nbr in serials:
data['previous'] = serial_elem.get(str(nbr), None)
break
# next
for nbr in range(current + 1, max(serials)):
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 """