Moar stuffs:

- Expose part_detail and order_detail to SOLineItem serializer
- Update SalesOrder line item table
This commit is contained in:
Oliver Walters 2020-04-21 08:57:13 +10:00
parent a2c0c7c76a
commit 617fbf2f02
5 changed files with 72 additions and 6 deletions

View File

@ -80,6 +80,7 @@ class SalesOrderLineItemAdmin(ImportExportModelAdmin):
list_display = (
'order',
'part',
'quantity',
'reference'
)

View File

@ -20,7 +20,7 @@ from .models import PurchaseOrder, PurchaseOrderLineItem
from .serializers import POSerializer, POLineItemSerializer
from .models import SalesOrder, SalesOrderLineItem
from .serializers import SalseOrderSerializer, SOLineItemSerializer
from .serializers import SalesOrderSerializer, SOLineItemSerializer
class POList(generics.ListCreateAPIView):
@ -196,7 +196,7 @@ class SOList(generics.ListCreateAPIView):
"""
queryset = SalesOrder.objects.all()
serializer_class = SalseOrderSerializer
serializer_class = SalesOrderSerializer
def get_serializer(self, *args, **kwargs):
@ -219,7 +219,7 @@ class SOList(generics.ListCreateAPIView):
'lines'
)
queryset = SalseOrderSerializer.annotate_queryset(queryset)
queryset = SalesOrderSerializer.annotate_queryset(queryset)
return queryset
@ -269,7 +269,7 @@ class SODetail(generics.RetrieveUpdateAPIView):
"""
queryset = SalesOrder.objects.all()
serializer_class = SalseOrderSerializer
serializer_class = SalesOrderSerializer
def get_serializer(self, *args, **kwargs):
@ -288,7 +288,7 @@ class SODetail(generics.RetrieveUpdateAPIView):
queryset = queryset.prefetch_related('customer', 'lines')
queryset = SalseOrderSerializer.annotate_queryset(queryset)
queryset = SalesOrderSerializer.annotate_queryset(queryset)
return queryset
@ -303,6 +303,32 @@ class SOLineItemList(generics.ListCreateAPIView):
queryset = SalesOrderLineItem.objects.all()
serializer_class = SOLineItemSerializer
def get_serializer(self, *args, **kwargs):
try:
kwargs['part_detail'] = str2bool(self.request.query_params.get('part_detail', False))
except AttributeError:
pass
try:
kwargs['order_detail'] = str2bool(self.request.query_params.get('order_detail', False))
except AttributeError:
pass
kwargs['context'] = self.get_serializer_context()
return self.serializer_class(*args, **kwargs)
def get_queryset(self, *args, **kwargs):
queryset = super().get_queryset(*args, **kwargs)
return queryset.prefetch_related(
'part',
'part__stock_items',
'order',
)
permission_classes = [permissions.IsAuthenticated]
filter_backends = [DjangoFilterBackend]

View File

@ -11,6 +11,7 @@ from django.db.models import Count
from InvenTree.serializers import InvenTreeModelSerializer
from company.serializers import CompanyBriefSerializer
from part.serializers import PartBriefSerializer
from .models import PurchaseOrder, PurchaseOrderLineItem
from .models import SalesOrder, SalesOrderLineItem
@ -86,7 +87,7 @@ class POLineItemSerializer(InvenTreeModelSerializer):
]
class SalseOrderSerializer(InvenTreeModelSerializer):
class SalesOrderSerializer(InvenTreeModelSerializer):
"""
Serializers for the SalesOrder object
"""
@ -145,6 +146,22 @@ class SalseOrderSerializer(InvenTreeModelSerializer):
class SOLineItemSerializer(InvenTreeModelSerializer):
""" Serializer for a SalesOrderLineItem object """
def __init__(self, *args, **kwargs):
part_detail = kwargs.pop('part_detail', False)
order_detail = kwargs.pop('order_detail', False)
super().__init__(*args, **kwargs)
if part_detail is not True:
self.fields.pop('part_detail')
if order_detail is not True:
self.fields.pop('order_detail')
order_detail = SalesOrderSerializer(source='order', many=False, read_only=True)
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
class Meta:
model = SalesOrderLineItem
@ -154,4 +171,7 @@ class SOLineItemSerializer(InvenTreeModelSerializer):
'reference',
'notes',
'order',
'order_detail',
'part',
'part_detail',
]

View File

@ -32,6 +32,7 @@ $("#so-lines-table").inventreeTable({
formatNoMatches: function() { return "No matching line items"; },
queryParams: {
order: {{ order.id }},
part_detail: true,
},
url: "{% url 'api-so-line-list' %}",
columns: [
@ -40,6 +41,18 @@ $("#so-lines-table").inventreeTable({
title: 'ID',
visible: false,
},
{
sortable: true,
field: 'part',
title: 'Part',
formatter: function(value, row, index, field) {
if (row.part) {
return imageHoverIcon(row.part_detail.thumbnail) + renderLink(row.part_detail.full_name, `/part/${value}/`);
} else {
return '-';
}
}
},
{
sortable: true,
field: 'reference',

View File

@ -61,6 +61,10 @@ purchase_order_urls = [
url(r'^.*$', views.PurchaseOrderIndex.as_view(), name='po-index'),
]
so_line_urls = [
url(r'^new/', views.SOLineItemCreate.as_view(), name='so-line-item-create'),
]
sales_order_detail_urls = [
url(r'^edit/', views.SalesOrderEdit.as_view(), name='so-edit'),
@ -75,6 +79,8 @@ sales_order_urls = [
url(r'^new/', views.SalesOrderCreate.as_view(), name='so-create'),
url(r'^line/', include(so_line_urls)),
# Display detail view for a single SalesOrder
url(r'^(?P<pk>\d+)/', include(sales_order_detail_urls)),