Coverage for apps/products/views.py: 88%
26 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-27 13:33 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-27 13:33 -0600
1from django.db.models import ProtectedError
2from rest_framework.exceptions import ValidationError
3from rest_framework.mixins import CreateModelMixin as Create
4from rest_framework.mixins import DestroyModelMixin as Delete
5from rest_framework.mixins import ListModelMixin as List
6from rest_framework.mixins import RetrieveModelMixin as Detail
7from rest_framework.mixins import UpdateModelMixin as Update
8from rest_framework.viewsets import GenericViewSet
10from apps.users.mixins import AdminMixin
12from .serializers import (
13 ProductCategorySerializer,
14 ProductSerializer,
15 ProductVariationClientSerializer,
16 ProductVariationSerializer,
17)
20class AdminProductCategoryViewSet(AdminMixin, GenericViewSet, Create, List, Detail, Update, Delete):
21 """
22 Product Category ViewSet for Admin
23 """
25 serializer_class = ProductCategorySerializer
26 filterset_fields = ["size_category"]
29class AdminProductViewSet(AdminMixin, GenericViewSet, Create, List, Detail, Update, Delete):
30 """
31 Product ViewSet for Admin
32 """
34 serializer_class = ProductSerializer
35 filterset_fields = ["product_category", "is_active"]
38class AdminProductVariationViewSet(AdminMixin, GenericViewSet, Create, List, Detail, Update, Delete):
39 """
40 Product Variation ViewSet for Admin
41 """
43 serializer_class = ProductVariationSerializer
44 filterset_fields = ["product", "clients"]
46 def destroy(self, request, *args, **kwargs):
47 try:
48 return super().destroy(request)
49 except ProtectedError:
50 return ValidationError({"detail": "No se puede eliminar la variacion porque esta referenciada en ordenes"})
53class AdminProductVariationClientViewSet(AdminMixin, GenericViewSet, Create, Update, Delete):
54 """
55 Product Variation Client ViewSet for Admin
56 """
58 serializer_class = ProductVariationClientSerializer