uncloud/uncloud/uncloud_pay/views.py

56 lines
857 B
Python
Raw Normal View History

2020-02-27 10:21:38 +00:00
from django.shortcuts import render
# Create your views here.
# to be implemented
class BalanceViewSet(viewsets.ModelViewSet):
# here we return a number
# number = sum(payments) - sum(bills)
bills = Bills.objects.filter(owner=self.request.user)
payments = Payment.objects.filter(owner=self.request.user)
# sum_paid = sum([ amount for amount payments..,. ]) # you get the picture
# sum_to_be_paid = sum([ amount for amount bills..,. ]) # you get the picture
class Bills(viewset.ModelViewSet):
def unpaid(self, request):
return Bills.objects.filter(owner=self.request.user, paid=False)
serializer_class = BillSerializer
permission_classes = [permissions.IsAuthenticated]
http_method_names = ['get']
def get_queryset(self):
return self.request.user.get_bills()