Merge branch 'bill-id' of code.ungleich.ch:nico/meow-pay
This commit is contained in:
commit
0032c272e7
4 changed files with 30 additions and 28 deletions
|
@ -9,8 +9,6 @@ from datetime import timedelta, date
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from uncloud_pay.models import Bill
|
from uncloud_pay.models import Bill
|
||||||
|
|
||||||
BILL_PAYMENT_DELAY=timedelta(days=10)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -31,8 +29,7 @@ class Command(BaseCommand):
|
||||||
Bill.generate_for(
|
Bill.generate_for(
|
||||||
year=now.year,
|
year=now.year,
|
||||||
month=now.month,
|
month=now.month,
|
||||||
user=user,
|
user=user)
|
||||||
allowed_delay=BILL_PAYMENT_DELAY)
|
|
||||||
|
|
||||||
# We're done for this round :-)
|
# We're done for this round :-)
|
||||||
print("=> Done.")
|
print("=> Done.")
|
||||||
|
|
|
@ -180,6 +180,12 @@ class Bill(models.Model):
|
||||||
|
|
||||||
valid = models.BooleanField(default=True)
|
valid = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reference(self):
|
||||||
|
return "{}_{}".format(
|
||||||
|
self.owner.username,
|
||||||
|
self.creation_date.strftime("%Y-%m-%d-%H%M"))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def records(self):
|
def records(self):
|
||||||
bill_records = []
|
bill_records = []
|
||||||
|
|
|
@ -47,27 +47,6 @@ class CreatePaymentMethodSerializer(serializers.ModelSerializer):
|
||||||
model = PaymentMethod
|
model = PaymentMethod
|
||||||
fields = ['source', 'description', 'primary', 'credit_card']
|
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.
|
# Orders & Products.
|
||||||
|
|
||||||
|
@ -83,3 +62,26 @@ class OrderSerializer(serializers.ModelSerializer):
|
||||||
model = Order
|
model = Order
|
||||||
fields = ['uuid', 'creation_date', 'starting_date', 'ending_date',
|
fields = ['uuid', 'creation_date', 'starting_date', 'ending_date',
|
||||||
'bill', 'recurring_period', 'records', 'recurring_price', 'one_time_price']
|
'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 = ['reference', 'owner', 'total', 'due_date', 'creation_date',
|
||||||
|
'starting_date', 'ending_date', 'records', 'final']
|
||||||
|
|
|
@ -34,9 +34,6 @@ class BillViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Bill.objects.filter(owner=self.request.user)
|
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):
|
class PaymentViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
serializer_class = PaymentSerializer
|
serializer_class = PaymentSerializer
|
||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
Loading…
Reference in a new issue