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
commit a2870b60d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -247,7 +247,19 @@
<tr>
<td><span class='fas fa-hashtag'></span></td>
<td>{% trans "Serial Number" %}</td>
<td>{{ item.serial }}</td>
<td>
{% if previous %}
<a class="btn btn-default" aria-label="{% trans 'previous page' %}" href="{% url request.resolver_match.url_name previous.id %}">
<small>{{ previous.serial }}</small>
</a>
{% endif %}
<span class="btn" href=""><strong>{{ item.serial }}</strong></span>
{% if next %}
<a class="btn btn-default text-sm" aria-label="{% trans 'next page' %}" href="{% url request.resolver_match.url_name next.id %}">
<small>{{ next.serial }}</small>
</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, -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 """