mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
prev and next serial link in stock items
This commit is contained in:
parent
369acb494b
commit
1786c029b4
@ -247,7 +247,16 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-hashtag'></span></td>
|
<td><span class='fas fa-hashtag'></span></td>
|
||||||
<td>{% trans "Serial Number" %}</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>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -86,6 +86,29 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
queryset = StockItem.objects.all()
|
queryset = StockItem.objects.all()
|
||||||
model = StockItem
|
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):
|
class StockItemNotes(InvenTreeRoleMixin, UpdateView):
|
||||||
""" View for editing the 'notes' field of a StockItem object """
|
""" View for editing the 'notes' field of a StockItem object """
|
||||||
|
Loading…
Reference in New Issue
Block a user