add: add new api for expence
This commit is contained in:
@@ -57,8 +57,11 @@ class ExpenceListApiView(generics.GenericAPIView):
|
||||
|
||||
def get(self, request):
|
||||
cash_transaction_ids = request.query_params.getlist('cash_transaction')
|
||||
status = request.query_params.get('status')
|
||||
if cash_transaction_ids:
|
||||
self.queryset = self.queryset.filter(cash_transaction__in=cash_transaction_ids)
|
||||
self.queryset = self.queryset.filter(cash_transaction__in=cash_transaction_ids).distinct()
|
||||
if status:
|
||||
self.queryset = self.queryset.filter(status=status).distinct()
|
||||
page = self.paginate_queryset(self.filter_queryset(self.queryset))
|
||||
if page is not None:
|
||||
serializer = self.serializer_class(page, many=True)
|
||||
@@ -80,4 +83,28 @@ class CounterpartyExpenceListApiView(generics.GenericAPIView):
|
||||
if page is not None:
|
||||
ser = self.serializer_class(page, many=True)
|
||||
return self.get_paginated_response(ser.data)
|
||||
|
||||
|
||||
|
||||
class ChangeExpenceStatusApiView(views.APIView):
|
||||
permission_classes = [HasRolePermission]
|
||||
|
||||
def post(self, request, id):
|
||||
expence = get_object_or_404(Expence, id=id)
|
||||
status = request.data.get('status', None)
|
||||
if status is None:
|
||||
return Response(
|
||||
{
|
||||
'success': False,
|
||||
'message': 'status field is required, choices PENDING, CANCELLED, CONFIRMED'
|
||||
},
|
||||
status=400
|
||||
)
|
||||
expence.status = status
|
||||
expence.save()
|
||||
return Response(
|
||||
{
|
||||
'success': True,
|
||||
'message': 'expence status successfully updated',
|
||||
},
|
||||
status=200
|
||||
)
|
||||
Reference in New Issue
Block a user