Coverage for apps/payments/views.py: 77%
31 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-23 08:26 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-23 08:26 -0600
1from rest_framework.mixins import CreateModelMixin as Create
2from rest_framework.mixins import ListModelMixin as List
3from rest_framework.mixins import RetrieveModelMixin as Detail
4from rest_framework.viewsets import GenericViewSet
6from apps.users.mixins import UserMixin
8from .serializers import (
9 OrganizationPaymentMethodSerializer,
10 PaymentAllocationSerializer,
11 PaymentExportSerializer,
12 PaymentSerializer,
13 SessionSerializer,
14)
17class UserSessionViewSet(UserMixin, GenericViewSet, Create):
18 """
19 Session ViewSet for User
20 """
22 serializer_class = SessionSerializer
24 def create(self, request, *args, **kwargs):
25 request.data["practitioner"] = request.user.practitioner.pk
26 return super().create(request, args, kwargs)
29class UserOrganizationPaymentMethodViewSet(UserMixin, GenericViewSet, List):
30 """
31 Organization Payment Method ViewSet for User
32 """
34 serializer_class = OrganizationPaymentMethodSerializer
35 filterset_fields = ["organization"]
37 def get_queryset(self, *args, **kwargs):
38 return super().get_queryset().filter(organization__in=self.user.affiliations.values_list("organization"))
41class UserPaymentViewSet(UserMixin, GenericViewSet, Create, List, Detail):
42 """
43 Payment ViewSet for User
44 """
46 serializer_class = PaymentSerializer
47 filterset_fields = ["appointment__patient"]
49 def perform_create(self, serializer):
50 user = getattr(self.request, "user", None)
51 serializer.save(created_by=user)
54class UserPaymentAllocationViewSet(UserMixin, GenericViewSet, Create, List, Detail):
55 """
56 PaymentAllocation ViewSet for User
57 """
59 serializer_class = PaymentAllocationSerializer
60 filterset_fields = ["appointment_charge__appointment"]
63class UserPaymentExportViewSet(UserMixin, GenericViewSet, Create):
64 """
65 ViewSet for PaymentExport
66 """
68 serializer_class = PaymentExportSerializer
70 def create(self, request, *args, **kwargs):
71 if hasattr(self.user, "practitioner") and getattr(request.data, "practitioner", False):
72 request.data["practitioner"] = self.user.practitioner.pk
73 return super().create(request, args, kwargs)