Merge pull request #1894 from SchrodingersGat/non-int-serial-fix

Fix for non-integer serial numbers

(cherry picked from commit 529742b520)
This commit is contained in:
Oliver 2021-08-03 10:03:05 +10:00
parent b18f360daf
commit 073bb7c488
2 changed files with 32 additions and 14 deletions

View File

@ -253,7 +253,7 @@
<small>{{ previous.serial }}</small>
</a>
{% endif %}
<span class="btn" href=""><strong>{{ item.serial }}</strong></span>
{{ item.serial }}
{% 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>

View File

@ -92,12 +92,26 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
data = super().get_context_data(**kwargs)
if self.object.serialized:
serial_elem = {int(a.serial): a for a in self.object.part.stock_items.all() if a.serialized}
serials = serial_elem.keys()
serial_elem = {}
try:
current = int(self.object.serial)
for item in self.object.part.stock_items.all():
if item.serialized:
try:
sn = int(item.serial)
serial_elem[sn] = item
except ValueError:
# We only support integer serial number progression
pass
serials = serial_elem.keys()
# previous
for nbr in range(current - 1, -1, -1):
for nbr in range(current - 1, min(serials), -1):
if nbr in serials:
data['previous'] = serial_elem.get(nbr, None)
break
@ -108,6 +122,10 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
data['next'] = serial_elem.get(nbr, None)
break
except ValueError:
# We only support integer serial number progression
pass
return data
def get(self, request, *args, **kwargs):