From 1ca247148c79620213b31260dabfbef90fb338d3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 27 Feb 2020 11:21:38 +0100 Subject: [PATCH] [uncloud_pay] add "prototype" --- uncloud/uncloud_pay/__init__.py | 0 uncloud/uncloud_pay/admin.py | 3 + uncloud/uncloud_pay/apps.py | 5 ++ uncloud/uncloud_pay/migrations/__init__.py | 0 uncloud/uncloud_pay/models.py | 91 ++++++++++++++++++++++ uncloud/uncloud_pay/tests.py | 3 + uncloud/uncloud_pay/views.py | 55 +++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 uncloud/uncloud_pay/__init__.py create mode 100644 uncloud/uncloud_pay/admin.py create mode 100644 uncloud/uncloud_pay/apps.py create mode 100644 uncloud/uncloud_pay/migrations/__init__.py create mode 100644 uncloud/uncloud_pay/models.py create mode 100644 uncloud/uncloud_pay/tests.py create mode 100644 uncloud/uncloud_pay/views.py diff --git a/uncloud/uncloud_pay/__init__.py b/uncloud/uncloud_pay/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/uncloud_pay/admin.py b/uncloud/uncloud_pay/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/uncloud/uncloud_pay/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/uncloud/uncloud_pay/apps.py b/uncloud/uncloud_pay/apps.py new file mode 100644 index 0000000..051ffb4 --- /dev/null +++ b/uncloud/uncloud_pay/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UncloudPayConfig(AppConfig): + name = 'uncloud_pay' diff --git a/uncloud/uncloud_pay/migrations/__init__.py b/uncloud/uncloud_pay/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py new file mode 100644 index 0000000..6910d58 --- /dev/null +++ b/uncloud/uncloud_pay/models.py @@ -0,0 +1,91 @@ +from django.db import models +from django.contrib.auth import get_user_model + +# Create your models here. + + +class Bill(models.Model): + owner = models.ForeignKey(get_user_model(), + on_delete=models.CASCADE, + editable=False) + + creation_date = models.DateTimeField() + starting_date = models.DateTimeField() + ending_date = models.DateTimeField() + due_date = models.DateField() + + paid = models.BooleanField(default=False) + valid = models.BooleanField(default=True) + + @property + def amount(self): + # iterate over all related orders + pass + + +class Order(models.Model): + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + owner = models.ForeignKey(get_user_model(), + on_delete=models.CASCADE, + editable=False) + + creation_date = models.DateTimeField() + starting_date = models.DateTimeField() + ending_date = models.DateTimeField(blank=True, + null=True) + + bill = models.ManyToManyField(Bill, + on_delete=models.CASCADE, + editable=False, + blank=True, + null=True) + + + recurring_price = models.FloatField(editable=False) + one_time_price = models.FloatField(editable=False) + + recurring_period = models.CharField(max_length=32, + choices = ( + ('onetime', 'Onetime'), + ('per_year', 'Per Year'), + ('per_month', 'Per Month'), + ('per_week', 'Per Week'), + ('per_day', 'Per Day'), + ('per_hour', 'Per Hour'), + ('per_minute', 'Per Minute'), + ('per_second', 'Per Second'), + ), + default='onetime' + + ) + + # def amount(self): + # amount = recurring_price + # if recurring and first_month: + # amount += one_time_price + + # return amount # you get the picture + + + +class Payment(models.Model): + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + + owner = models.ForeignKey(get_user_model(), + on_delete=models.CASCADE, + editable=False) + + amount = models.DecimalField( + default=0.0, + validators=[MinValueValidator(0)]) + + source = models.CharField(max_length=256, + choices = ( + ('wire', 'Wire Transfer'), + ('strip', 'Stripe'), + ('voucher', 'Voucher'), + ('referral', 'Referral'), + ('unknown', 'Unknown') + ), + default='unknown') + timestamp = models.DateTimeField(editable=False) diff --git a/uncloud/uncloud_pay/tests.py b/uncloud/uncloud_pay/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/uncloud/uncloud_pay/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/uncloud/uncloud_pay/views.py b/uncloud/uncloud_pay/views.py new file mode 100644 index 0000000..b52a2b6 --- /dev/null +++ b/uncloud/uncloud_pay/views.py @@ -0,0 +1,55 @@ +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()