Coverage for apps/invoices/views.py: 71%
26 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-23 06:56 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-23 06:56 -0600
1from rest_framework.mixins import CreateModelMixin as Create
2from rest_framework.mixins import DestroyModelMixin as Delete
3from rest_framework.mixins import ListModelMixin as List
4from rest_framework.mixins import RetrieveModelMixin as Detail
5from rest_framework.mixins import UpdateModelMixin as Update
6from rest_framework.viewsets import GenericViewSet
8from apps.users.mixins import PublicMixin, UserMixin
10from .serializers import (
11 InvoiceUseSerializer,
12 PractitionerInvoiceConfigurationSerializer,
13 ProductInvoiceConfigurationSerializer,
14)
17class PublicInvoiceUseViewSet(PublicMixin, GenericViewSet, List):
18 """
19 Public ViewSet for Invoice Use
20 """
22 serializer_class = InvoiceUseSerializer
25class UserPractitionerInvoiceConfigurationViewSet(UserMixin, GenericViewSet, Create, List, Detail, Update):
26 """
27 User ViewSet for Practitioner Invoice Configuration
28 """
30 serializer_class = PractitionerInvoiceConfigurationSerializer
32 def get_object(self):
33 practitioner = getattr(self.request.user, 'practitioner', None)
34 if practitioner:
35 return getattr(practitioner, 'invoice_configuration', None)
36 return None
38 def perform_create(self, serializer):
39 serializer.save(practitioner=self.user.practitioner)
41 def get_queryset(self):
42 queryset = super().get_queryset()
43 return queryset.filter(practitioner=self.request.user.practitioner)
45 def list(self, request, *args, **kwargs):
46 return self.retrieve(request, *args, **kwargs)
49class UserProductInvoiceConfigurationViewSet(UserMixin, GenericViewSet, Create, Detail, Update, Delete):
50 """
51 User ViewSet for Product Invoice Configuration
52 """
54 serializer_class = ProductInvoiceConfigurationSerializer