mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added StockTracking API
/api/stock/track/ ListCreate API view StockItem page now shows bootrap-table of tracking notes
This commit is contained in:
parent
002c047105
commit
f2982a59ad
@ -7,8 +7,11 @@ from django.conf.urls import url, include
|
||||
|
||||
# from InvenTree.models import FilterChildren
|
||||
from .models import StockLocation, StockItem
|
||||
from .models import StockItemTracking
|
||||
|
||||
from .serializers import StockItemSerializer, StockQuantitySerializer
|
||||
from .serializers import LocationSerializer
|
||||
from .serializers import StockTrackingSerializer
|
||||
|
||||
from InvenTree.views import TreeSerializer
|
||||
from InvenTree.serializers import DraftRUDView
|
||||
@ -242,19 +245,34 @@ class StockStocktakeEndpoint(generics.UpdateAPIView):
|
||||
return response.Response(serializer.data)
|
||||
|
||||
|
||||
class AddStockEndpoint(generics.UpdateAPIView):
|
||||
class StockTrackingList(generics.ListCreateAPIView):
|
||||
|
||||
queryset = StockItem.objects.all()
|
||||
serializer_class = StockQuantitySerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
queryset = StockItemTracking.objects.all()
|
||||
serializer_class = StockTrackingSerializer
|
||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly,]
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
object = self.get_object()
|
||||
object.add_stock(request.data['quantity'])
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
filters.SearchFilter,
|
||||
filters.OrderingFilter,
|
||||
]
|
||||
|
||||
serializer = self.get_serializer(object)
|
||||
filter_fields = [
|
||||
'item',
|
||||
'user',
|
||||
]
|
||||
|
||||
ordering = '-date'
|
||||
|
||||
ordering_fields = [
|
||||
'date',
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
'title',
|
||||
'notes',
|
||||
]
|
||||
|
||||
return response.Response(serializer.data)
|
||||
|
||||
|
||||
class LocationDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
@ -297,6 +315,8 @@ stock_api_urls = [
|
||||
|
||||
url(r'move/?', StockMove.as_view(), name='api-stock-move'),
|
||||
|
||||
url(r'track/?', StockTrackingList.as_view(), name='api-stock-track'),
|
||||
|
||||
url(r'^tree/?', StockCategoryTree.as_view(), name='api-stock-tree'),
|
||||
|
||||
url(r'^.*$', StockList.as_view(), name='api-stock-list'),
|
||||
|
@ -320,6 +320,9 @@ class StockItemTracking(models.Model):
|
||||
""" Stock tracking entry
|
||||
"""
|
||||
|
||||
def get_absolute_url(self):
|
||||
return '/stock/track/{id}/'.format(id=self.id)
|
||||
|
||||
# Stock item
|
||||
item = models.ForeignKey(StockItem, on_delete=models.CASCADE,
|
||||
related_name='tracking_info')
|
||||
|
@ -1,6 +1,7 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import StockItem, StockLocation
|
||||
from .models import StockItemTracking
|
||||
|
||||
from part.serializers import PartBriefSerializer
|
||||
|
||||
@ -19,6 +20,30 @@ class LocationBriefSerializer(serializers.ModelSerializer):
|
||||
]
|
||||
|
||||
|
||||
class StockTrackingSerializer(serializers.ModelSerializer):
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StockItemTracking
|
||||
fields = [
|
||||
'pk',
|
||||
'url',
|
||||
'item',
|
||||
'date',
|
||||
'title',
|
||||
'notes',
|
||||
'user',
|
||||
'system',
|
||||
]
|
||||
|
||||
read_only_fields = [
|
||||
'date',
|
||||
'user',
|
||||
'system',
|
||||
]
|
||||
|
||||
|
||||
class StockItemSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for a StockItem
|
||||
"""
|
||||
|
@ -113,17 +113,8 @@
|
||||
</div>
|
||||
<div id="collapse1" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<ul class="list-group">
|
||||
{% for track in item.tracking_info.all %}
|
||||
<li class='list-group-item'>
|
||||
<b>{{ track.title }}</b>
|
||||
{% if track.notes %}
|
||||
<br>{{ track.notes }}
|
||||
{% endif %}
|
||||
<span class='badge'>{{ track.date }}{% if track.user %} - {{ track.user }}{% endif %}</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<table class='table table-condensed table-striped' id='track-table'>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -185,4 +176,38 @@
|
||||
redirect: "{% url 'part-stock' item.part.id %}"
|
||||
});
|
||||
});
|
||||
|
||||
$('#track-table').bootstrapTable({
|
||||
sortable: true,
|
||||
search: true,
|
||||
method: 'get',
|
||||
columns: [
|
||||
{
|
||||
field: 'date',
|
||||
title: 'Date',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'title',
|
||||
title: 'Description',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
var html = "<b>" + value + "</b>";
|
||||
|
||||
if (row.notes) {
|
||||
html += "<br><i>" + row.notes + "</i>";
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'user',
|
||||
title: 'User',
|
||||
}
|
||||
],
|
||||
url: "{% url 'api-stock-track' %}",
|
||||
})
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user