From 4016c28c5f4100db0fd9ff3ecee6b0e8aa91812d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 5 Mar 2020 11:27:43 +0100 Subject: [PATCH 1/3] Fix generate-bills --- uncloud/uncloud_pay/management/commands/generate-bills.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/uncloud/uncloud_pay/management/commands/generate-bills.py b/uncloud/uncloud_pay/management/commands/generate-bills.py index a7dbe78..5bd4519 100644 --- a/uncloud/uncloud_pay/management/commands/generate-bills.py +++ b/uncloud/uncloud_pay/management/commands/generate-bills.py @@ -9,8 +9,6 @@ from datetime import timedelta, date from django.utils import timezone from uncloud_pay.models import Bill -BILL_PAYMENT_DELAY=timedelta(days=10) - logger = logging.getLogger(__name__) class Command(BaseCommand): @@ -31,8 +29,7 @@ class Command(BaseCommand): Bill.generate_for( year=now.year, month=now.month, - user=user, - allowed_delay=BILL_PAYMENT_DELAY) + user=user) # We're done for this round :-) print("=> Done.") From c41b55573a27e7830c50ec607727be24ebb7d47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 6 Mar 2020 09:32:25 +0100 Subject: [PATCH 2/3] Fix order link in BillRecordSerializer --- uncloud/uncloud_pay/serializers.py | 44 ++++++++++++++++-------------- uncloud/uncloud_pay/views.py | 3 -- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index aa75fd9..d763590 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -47,27 +47,6 @@ class CreatePaymentMethodSerializer(serializers.ModelSerializer): model = PaymentMethod fields = ['source', 'description', 'primary', 'credit_card'] - -### -# Bills - -# TODO: remove magic numbers for decimal fields -class BillRecordSerializer(serializers.Serializer): - order = serializers.CharField() - description = serializers.CharField() - recurring_period = serializers.CharField() - recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2) - recurring_count = serializers.DecimalField(max_digits=10, decimal_places=2) - one_time_price = serializers.DecimalField(max_digits=10, decimal_places=2) - amount = serializers.DecimalField(max_digits=10, decimal_places=2) - -class BillSerializer(serializers.ModelSerializer): - records = BillRecordSerializer(many=True, read_only=True) - class Meta: - model = Bill - fields = ['owner', 'total', 'due_date', 'creation_date', - 'starting_date', 'ending_date', 'records', 'final'] - ### # Orders & Products. @@ -83,3 +62,26 @@ class OrderSerializer(serializers.ModelSerializer): model = Order fields = ['uuid', 'creation_date', 'starting_date', 'ending_date', 'bill', 'recurring_period', 'records', 'recurring_price', 'one_time_price'] + + +### +# Bills + +# TODO: remove magic numbers for decimal fields +class BillRecordSerializer(serializers.Serializer): + order = serializers.HyperlinkedRelatedField( + view_name='order-detail', + read_only=True) + description = serializers.CharField() + recurring_period = serializers.CharField() + recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2) + recurring_count = serializers.DecimalField(max_digits=10, decimal_places=2) + one_time_price = serializers.DecimalField(max_digits=10, decimal_places=2) + amount = serializers.DecimalField(max_digits=10, decimal_places=2) + +class BillSerializer(serializers.ModelSerializer): + records = BillRecordSerializer(many=True, read_only=True) + class Meta: + model = Bill + fields = ['owner', 'total', 'due_date', 'creation_date', + 'starting_date', 'ending_date', 'records', 'final'] diff --git a/uncloud/uncloud_pay/views.py b/uncloud/uncloud_pay/views.py index 38d1aa4..57c284d 100644 --- a/uncloud/uncloud_pay/views.py +++ b/uncloud/uncloud_pay/views.py @@ -34,9 +34,6 @@ class BillViewSet(viewsets.ReadOnlyModelViewSet): def get_queryset(self): return Bill.objects.filter(owner=self.request.user) - def unpaid(self, request): - return Bill.objects.filter(owner=self.request.user, paid=False) - class PaymentViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = PaymentSerializer permission_classes = [permissions.IsAuthenticated] From 658262c5993b2e3c18a9910920b09029cf2e948c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 6 Mar 2020 09:39:41 +0100 Subject: [PATCH 3/3] Add human readable reference to bills --- uncloud/uncloud_pay/models.py | 6 ++++++ uncloud/uncloud_pay/serializers.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index 43064e4..32d3eac 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -180,6 +180,12 @@ class Bill(models.Model): valid = models.BooleanField(default=True) + @property + def reference(self): + return "{}_{}".format( + self.owner.username, + self.creation_date.strftime("%Y-%m-%d-%H%M")) + @property def records(self): bill_records = [] diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index d763590..60ddc75 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -83,5 +83,5 @@ class BillSerializer(serializers.ModelSerializer): records = BillRecordSerializer(many=True, read_only=True) class Meta: model = Bill - fields = ['owner', 'total', 'due_date', 'creation_date', + fields = ['reference', 'owner', 'total', 'due_date', 'creation_date', 'starting_date', 'ending_date', 'records', 'final']