🔥 Remove stat and log views
➖ Remove djangorestframework
This commit is contained in:
1 parent
d7513f389e
commit
7ba3ead688
13 files changed
+67
-609
No files matched your search
@@ -7,7 +7,7 @@ from strawberry import ID
|
||||
|
||||
from main import models
|
||||
from main.api.errors import Error, FieldError, FormErrors
|
||||
from main.api.types import Order, Transaction, UserProfile
|
||||
from main.api.types import Order, Transaction
|
||||
|
||||
UserModel = get_user_model()
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
from django.db.models import Count, Sum
|
||||
from rest_framework import serializers
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
|
||||
from main.models import Order, OrderLine, Product
|
||||
|
||||
|
||||
class ProductSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ProductStatSerializer(ModelSerializer):
|
||||
EXTERNAL_USER = "Ekstern"
|
||||
counts = serializers.SerializerMethodField()
|
||||
|
||||
def _format_counts(self, per_user):
|
||||
per_user = list(per_user)
|
||||
for row in per_user:
|
||||
first = row.pop("order__customer__first_name")
|
||||
last = row.pop("order__customer__last_name")
|
||||
if first is None:
|
||||
who = self.EXTERNAL_USER
|
||||
else:
|
||||
who = "{} {}".format(first, last)
|
||||
row["full_name"] = who
|
||||
|
||||
return per_user
|
||||
|
||||
def get_counts(self, obj):
|
||||
name_fields = ["order__customer__first_name", "order__customer__last_name"]
|
||||
per_user = OrderLine.objects.filter(product=obj)
|
||||
per_user = per_user.values(*name_fields).annotate(amount_total=Sum("amount")).order_by("-amount_total")
|
||||
|
||||
return self._format_counts(per_user)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"image",
|
||||
"inventory_amount",
|
||||
"active",
|
||||
"created",
|
||||
"counts",
|
||||
]
|
||||
@@ -1,19 +0,0 @@
|
||||
from rest_framework import mixins
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
from main.api.serializers import ProductSerializer, ProductStatSerializer
|
||||
from main.models import Product
|
||||
|
||||
|
||||
class ProductViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, GenericViewSet):
|
||||
serializer_class = ProductSerializer
|
||||
queryset = Product.objects.all()
|
||||
|
||||
@action(detail=False, methods=["get"])
|
||||
def group_by_user(self, request):
|
||||
products = self.get_queryset().filter(active=True)
|
||||
serializer = ProductStatSerializer(products, many=True)
|
||||
|
||||
return Response(serializer.data)
|
||||
Reference in new issue
Block a user