mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Merge pull request #1757 from matmair/stock-next-prev
Stock previous / next serial
This commit is contained in:
		| @@ -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> | ||||
|   | ||||
| @@ -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 """ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user