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
937211288e
@ -33,6 +33,13 @@ class CompanyList(generics.ListCreateAPIView):
|
|||||||
serializer_class = CompanySerializer
|
serializer_class = CompanySerializer
|
||||||
queryset = Company.objects.all()
|
queryset = Company.objects.all()
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
|
||||||
|
queryset = super().get_queryset()
|
||||||
|
queryset = CompanySerializer.annotate_queryset(queryset)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
permissions.IsAuthenticated,
|
permissions.IsAuthenticated,
|
||||||
]
|
]
|
||||||
@ -68,6 +75,13 @@ class CompanyDetail(generics.RetrieveUpdateDestroyAPIView):
|
|||||||
queryset = Company.objects.all()
|
queryset = Company.objects.all()
|
||||||
serializer_class = CompanySerializer
|
serializer_class = CompanySerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
|
||||||
|
queryset = super().get_queryset()
|
||||||
|
queryset = CompanySerializer.annotate_queryset(queryset)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
permissions.IsAuthenticated,
|
permissions.IsAuthenticated,
|
||||||
]
|
]
|
||||||
|
@ -4,6 +4,8 @@ JSON serializers for Company app
|
|||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
from .models import Company
|
from .models import Company
|
||||||
from .models import SupplierPart, SupplierPriceBreak
|
from .models import SupplierPart, SupplierPriceBreak
|
||||||
|
|
||||||
@ -33,11 +35,21 @@ class CompanyBriefSerializer(InvenTreeModelSerializer):
|
|||||||
class CompanySerializer(InvenTreeModelSerializer):
|
class CompanySerializer(InvenTreeModelSerializer):
|
||||||
""" Serializer for Company object (full detail) """
|
""" Serializer for Company object (full detail) """
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def annotate_queryset(queryset):
|
||||||
|
|
||||||
|
return queryset.annotate(
|
||||||
|
parts_supplied=Count('supplied_parts'),
|
||||||
|
parts_manufactured=Count('manufactured_parts')
|
||||||
|
)
|
||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
part_count = serializers.CharField(read_only=True)
|
|
||||||
|
|
||||||
image = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
image = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
||||||
|
|
||||||
|
parts_supplied = serializers.IntegerField(read_only=True)
|
||||||
|
parts_manufactured = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Company
|
model = Company
|
||||||
fields = [
|
fields = [
|
||||||
@ -57,7 +69,8 @@ class CompanySerializer(InvenTreeModelSerializer):
|
|||||||
'is_manufacturer',
|
'is_manufacturer',
|
||||||
'is_supplier',
|
'is_supplier',
|
||||||
'notes',
|
'notes',
|
||||||
'part_count'
|
'parts_supplied',
|
||||||
|
'parts_manufactured',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user