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

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 

5 

6from apps.users.mixins import UserMixin 

7 

8from .serializers import ( 

9 OrganizationPaymentMethodSerializer, 

10 PaymentAllocationSerializer, 

11 PaymentExportSerializer, 

12 PaymentSerializer, 

13 SessionSerializer, 

14) 

15 

16 

17class UserSessionViewSet(UserMixin, GenericViewSet, Create): 

18 """ 

19 Session ViewSet for User 

20 """ 

21 

22 serializer_class = SessionSerializer 

23 

24 def create(self, request, *args, **kwargs): 

25 request.data["practitioner"] = request.user.practitioner.pk 

26 return super().create(request, args, kwargs) 

27 

28 

29class UserOrganizationPaymentMethodViewSet(UserMixin, GenericViewSet, List): 

30 """ 

31 Organization Payment Method ViewSet for User 

32 """ 

33 

34 serializer_class = OrganizationPaymentMethodSerializer 

35 filterset_fields = ["organization"] 

36 

37 def get_queryset(self, *args, **kwargs): 

38 return super().get_queryset().filter(organization__in=self.user.affiliations.values_list("organization")) 

39 

40 

41class UserPaymentViewSet(UserMixin, GenericViewSet, Create, List, Detail): 

42 """ 

43 Payment ViewSet for User 

44 """ 

45 

46 serializer_class = PaymentSerializer 

47 filterset_fields = ["appointment__patient"] 

48 

49 def perform_create(self, serializer): 

50 user = getattr(self.request, "user", None) 

51 serializer.save(created_by=user) 

52 

53 

54class UserPaymentAllocationViewSet(UserMixin, GenericViewSet, Create, List, Detail): 

55 """ 

56 PaymentAllocation ViewSet for User 

57 """ 

58 

59 serializer_class = PaymentAllocationSerializer 

60 filterset_fields = ["appointment_charge__appointment"] 

61 

62 

63class UserPaymentExportViewSet(UserMixin, GenericViewSet, Create): 

64 """ 

65 ViewSet for PaymentExport 

66 """ 

67 

68 serializer_class = PaymentExportSerializer 

69 

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)