mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge remote-tracking branch 'inventree/master'
This commit is contained in:
commit
e4872d9f67
@ -5,6 +5,8 @@ JSON API for the Stock app
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
from django_filters import NumberFilter
|
||||
|
||||
from rest_framework import status
|
||||
|
||||
from django.conf.urls import url, include
|
||||
from django.urls import reverse
|
||||
from django.http import JsonResponse
|
||||
@ -658,6 +660,43 @@ class StockTrackingList(generics.ListCreateAPIView):
|
||||
serializer_class = StockTrackingSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
try:
|
||||
kwargs['item_detail'] = str2bool(self.request.query_params.get('item_detail', False))
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))
|
||||
except:
|
||||
pass
|
||||
|
||||
kwargs['context'] = self.get_serializer_context()
|
||||
|
||||
return self.serializer_class(*args, **kwargs)
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" Create a new StockItemTracking object
|
||||
|
||||
Here we override the default 'create' implementation,
|
||||
to save the user information associated with the request object.
|
||||
"""
|
||||
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
# Record the user who created this Part object
|
||||
item = serializer.save()
|
||||
item.user = request.user
|
||||
item.system = False
|
||||
|
||||
# quantity field cannot be explicitly adjusted here
|
||||
item.quantity = item.item.quantity
|
||||
item.save()
|
||||
|
||||
headers = self.get_success_headers(serializer.data)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
||||
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
filters.SearchFilter,
|
||||
|
@ -207,11 +207,24 @@ class StockItemAttachmentSerializer(InvenTreeModelSerializer):
|
||||
class StockTrackingSerializer(InvenTreeModelSerializer):
|
||||
""" Serializer for StockItemTracking model """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
item_detail = kwargs.pop('item_detail', False)
|
||||
user_detail = kwargs.pop('user_detail', False)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if item_detail is not True:
|
||||
self.fields.pop('item_detail')
|
||||
|
||||
if user_detail is not True:
|
||||
self.fields.pop('user_detail')
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
user = UserSerializerBrief(many=False, read_only=True)
|
||||
item_detail = StockItemSerializerBrief(source='item', many=False, read_only=True)
|
||||
|
||||
item = StockItemSerializerBrief(many=False, read_only=True)
|
||||
user_detail = UserSerializerBrief(source='user', many=False, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StockItemTracking
|
||||
@ -219,12 +232,14 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
||||
'pk',
|
||||
'url',
|
||||
'item',
|
||||
'item_detail',
|
||||
'date',
|
||||
'title',
|
||||
'notes',
|
||||
'link',
|
||||
'quantity',
|
||||
'user',
|
||||
'user_detail',
|
||||
'system',
|
||||
]
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
return {
|
||||
ordering: '-date',
|
||||
item: {{ item.pk }},
|
||||
user_detail: true,
|
||||
};
|
||||
},
|
||||
url: "{% url 'api-stock-track' %}",
|
||||
|
@ -6,7 +6,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block settings %}
|
||||
<h4>{% transa "Part Parameter Templates" %}</h4>
|
||||
<h4>{% trans "Part Parameter Templates" %}</h4>
|
||||
|
||||
<div id='param-buttons'>
|
||||
<button class='btn btn-success' id='new-param'>{% trans "New Parameter" %}</button>
|
||||
|
@ -448,7 +448,7 @@ function loadStockTrackingTable(table, options) {
|
||||
if (value)
|
||||
{
|
||||
// TODO - Format the user's first and last names
|
||||
return value.username;
|
||||
return row.user_detail.username;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user