add: add cash transaction delete and update apis
This commit is contained in:
@@ -32,6 +32,13 @@ class CashTransactionListSerializer(serializers.ModelSerializer):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CashTransactionUpdateSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = CashTransaction
|
||||||
|
fields = [
|
||||||
|
'name', 'payment_type', 'employees', 'status', 'folder',
|
||||||
|
]
|
||||||
|
|
||||||
class CashTransactionCreateSerializer(serializers.Serializer):
|
class CashTransactionCreateSerializer(serializers.Serializer):
|
||||||
payment_type_id = serializers.UUIDField()
|
payment_type_id = serializers.UUIDField()
|
||||||
employee_ids = serializers.ListSerializer(child=serializers.UUIDField())
|
employee_ids = serializers.ListSerializer(child=serializers.UUIDField())
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ urlpatterns = [
|
|||||||
[
|
[
|
||||||
path('list/', cash_views.CashTransactionListApiView.as_view()),
|
path('list/', cash_views.CashTransactionListApiView.as_view()),
|
||||||
path('create/', cash_views.CashTransactionCreateApiView.as_view()),
|
path('create/', cash_views.CashTransactionCreateApiView.as_view()),
|
||||||
|
path('<uuid:id>/delete/', cash_views.CashTransactionDeleteApiView.as_view()),
|
||||||
|
path('<uuid:id>/update/', cash_views.CashTransactionUpdateApiView.as_view()),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
path('cash_transaction_folder/', include(
|
path('cash_transaction_folder/', include(
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
from rest_framework import generics
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
|
from rest_framework import generics, views
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from core.apps.finance.models import CashTransaction
|
from core.apps.finance.models import CashTransaction
|
||||||
from core.apps.finance.serializers import cash_transaction as serializers
|
from core.apps.finance.serializers import cash_transaction as serializers
|
||||||
@@ -19,3 +22,44 @@ class CashTransactionCreateApiView(generics.CreateAPIView):
|
|||||||
queryset = CashTransaction.objects.all()
|
queryset = CashTransaction.objects.all()
|
||||||
permission_classes = [HasRolePermission]
|
permission_classes = [HasRolePermission]
|
||||||
required_permissions = ['project', 'project_folder']
|
required_permissions = ['project', 'project_folder']
|
||||||
|
|
||||||
|
|
||||||
|
class CashTransactionUpdateApiView(generics.GenericAPIView):
|
||||||
|
serializer_class = serializers.CashTransactionUpdateSerializer
|
||||||
|
queryset = CashTransaction.objects.all()
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
|
||||||
|
def patch(self, request, id):
|
||||||
|
obj = get_object_or_404(CashTransaction, id=id)
|
||||||
|
ser = self.serializer_class(data=request.data, instance=obj, partial=True)
|
||||||
|
if ser.is_valid(raise_exception=True):
|
||||||
|
ser.save()
|
||||||
|
return Response(
|
||||||
|
{
|
||||||
|
'success': True,
|
||||||
|
'message': 'Cash Transaction successfully updated!'
|
||||||
|
},
|
||||||
|
status=200,
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
{
|
||||||
|
'success': False,
|
||||||
|
'message': ser.errors
|
||||||
|
},
|
||||||
|
status=400
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CashTransactionDeleteApiView(views.APIView):
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
|
||||||
|
def delete(self, request, id):
|
||||||
|
obj = get_object_or_404(CashTransaction, id=id)
|
||||||
|
obj.delete()
|
||||||
|
return Response(
|
||||||
|
{
|
||||||
|
'success': True,
|
||||||
|
'message': 'Cash Transaction deleted'
|
||||||
|
},
|
||||||
|
status=204
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user