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