mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
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:
parent
b18f360daf
commit
073bb7c488
@ -253,7 +253,7 @@
|
|||||||
<small>{{ previous.serial }}</small> ‹
|
<small>{{ previous.serial }}</small> ‹
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="btn" href=""><strong>{{ item.serial }}</strong></span>
|
{{ item.serial }}
|
||||||
{% if next %}
|
{% if next %}
|
||||||
<a class="btn btn-default text-sm" aria-label="{% trans 'next page' %}" href="{% url request.resolver_match.url_name next.id %}">
|
<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>
|
› <small>{{ next.serial }}</small>
|
||||||
|
@ -92,21 +92,39 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
if self.object.serialized:
|
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()
|
|
||||||
current = int(self.object.serial)
|
|
||||||
|
|
||||||
# previous
|
serial_elem = {}
|
||||||
for nbr in range(current - 1, -1, -1):
|
|
||||||
if nbr in serials:
|
|
||||||
data['previous'] = serial_elem.get(nbr, None)
|
|
||||||
break
|
|
||||||
|
|
||||||
# next
|
try:
|
||||||
for nbr in range(current + 1, max(serials) + 1):
|
current = int(self.object.serial)
|
||||||
if nbr in serials:
|
|
||||||
data['next'] = serial_elem.get(nbr, None)
|
for item in self.object.part.stock_items.all():
|
||||||
break
|
|
||||||
|
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, min(serials), -1):
|
||||||
|
if nbr in serials:
|
||||||
|
data['previous'] = serial_elem.get(nbr, None)
|
||||||
|
break
|
||||||
|
|
||||||
|
# next
|
||||||
|
for nbr in range(current + 1, max(serials) + 1):
|
||||||
|
if nbr in serials:
|
||||||
|
data['next'] = serial_elem.get(nbr, None)
|
||||||
|
break
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
# We only support integer serial number progression
|
||||||
|
pass
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user